data_gen_cs generates simulated cross-sectional data based on the stochastic frontier model, allowing for different distributional assumptions for the one-sided technical inefficiency error term (\(u\)) and the two-sided idiosyncratic error term (\(v\)). The model has the general form:
\(Y = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + v - u\)
where \(u \geq 0\) and represents inefficiency. All variants are produced so that the user can select those that they want.
data_gen_cs(N, rand, sig_u, sig_v, cons, beta1, beta2, a, mu, sig_w = sig_u,
shape_g = 2, m_nak = 1, mu_ln = -0.5, k_w = 1.5, lam_tsl = 1.5)A data frame containing \(N\) observations with the following columns:
Individual identifier (simply \(1\) to \(N\)).
The constant term value.
Simulated explanatory variable \(x_1\).
Simulated explanatory variable \(x_2\).
The simulated one-sided error terms under different distributions.
Rayleigh one-sided error term, for y_pcs_r. Drawn on the convention sfm's "NR" uses, \(E[u^2] = \sigma_u^2\), so the Rayleigh scale is \(\sigma_u/\sqrt{2}\), \(E[u] = \sigma_u\sqrt{\pi}/2\) and \(Var(u) = (1-\pi/4)\sigma_u^2\).
The simulated two-sided error terms under different distributions.
The common Gamma(a/2, a/2) scale-mixing variable behind y_pcs_st; both of that column's components are divided by its square root, which is what makes the composed error skew-t.
The dependent variable \(Y\) under the corresponding SFA model distributions.
Normal-Rayleigh dependent variable, for sfm's "NR". Use this column, not y_pcs: the normal-Rayleigh and normal-half-normal composed errors are different families, not reparameterizations of one another, and "NR" cannot recover y_pcs's parameters. True values are \((\sigma_v, \sigma_u) = \) (sig_v, sig_u).
The auxiliary variable used for heteroskedasticity in y_pcs_z, y_pcs_ez, y_tthn_z, and y_zisf_z.
Exponential one-sided error term with heteroskedastic scale, for y_pcs_ez.
The second one-sided error component (\(w\)) for the two-tier columns below, under exponential, homoskedastic half-normal, and heteroskedastic half-normal distributions respectively.
A second auxiliary variable used for heteroskedasticity of \(\sigma_w\) in y_tthn_z.
Homoskedastic two-tier dependent variable (\(v + w - u\), both one-sided components exponential), for ttsfm's "TTNE"/"TTNLS".
Homoskedastic two-tier dependent variable (both one-sided components half-normal), for ttsfm's "TTHN" with no pipes.
Heteroskedastic two-tier dependent variable (\(\sigma_u\) a function of z, \(\sigma_w\) a function of zp), for ttsfm's "TTHN" with formula ~x1+x2|z|zp.
Indicator (1 = efficient, \(u\) forced to 0) used to build the zero-inefficiency columns below.
The true heteroskedastic "efficient regime" probability used to draw eff_ind_z.
Zero-inefficiency dependent variable with constant efficient-regime probability, for zsfm's "ZISF".
Zero-inefficiency dependent variable with z-dependent efficient-regime probability, for zsfm's "ZISF_Z".
Gamma one-sided error term and the corresponding dependent variable, for sfm's "NG". Shape shape_g, scale sig_u/shape_g, so \(E[u] = \sigma_u\) whatever shape is chosen.
Nakagami one-sided error term and dependent variable, for sfm's "NNAK". Shape m_nak, spread \(\Omega = \sigma_u^2\). The default m_nak = 1 is the Rayleigh case, so this column coincides in distribution with y_pcs_r at the default.
Generalized-exponential one-sided error term and dependent variable, for sfm's "NGE", drawn as \(u = -\sigma_u\log(1 - \sqrt{U})\) with \(U \sim \mathrm{Unif}(0,1)\).
Lognormal one-sided error term and dependent variable, for sfm's "NLN". Log-scale mean mu_ln and log-scale standard deviation sig_u.
Weibull one-sided error term and dependent variable, for sfm's "NW". Shape k_w, scale sig_u.
A constant column set to 1, potentially for use in estimation.
A single integer specifying the number of observations (cross-sectional units).
A single integer to set the seed for the random number generator, ensuring reproducibility.
The standard deviation parameter (\(\sigma_u\)) for the base distribution of the one-sided error term \(u\).
The standard deviation parameter (\(\sigma_v\)) for the base distribution of the two-sided error term \(v\).
The value of the constant term (intercept) in the model.
The coefficient for the \(x_1\) variable.
The coefficient for the \(x_2\) variable.
The degrees of freedom parameter for the t half-t distribution (u_t and v_t, respectively). Requires the rt function.
The mean parameter (\(\mu\)) for the normal truncated normal distribution (u_tn). Requires the rtruncnorm function.
The standard deviation/scale parameter (\(\sigma_w\)) for the second one-sided error component \(w\), used to generate two-tier model columns (see ttsfm). Defaults to sig_u.
Shape of the gamma inefficiency draw behind y_pcs_g, which targets sfm(model_name = "NG"). The scale is set to sig_u/shape_g, so \(E[u] = \sigma_u\) regardless of the shape chosen. sfm()'s NG likelihood reports the shape as mu and the scale as sigu, so the values to recover are shape_g and sig_u/shape_g.
Nakagami shape \(m\) behind y_pcs_nak, which targets sfm(model_name = "NNAK"). The spread is \(\Omega = \sigma_u^2\), so \(\sigma_u\) is the root-mean-square of \(u\). The default 1 is the Rayleigh case; 0.5 would collapse the Nakagami onto the half-normal and so duplicate y_pcs.
Log-scale mean of the lognormal inefficiency draw behind y_pcs_ln, which targets sfm(model_name = "NLN"). The log-scale standard deviation is sig_u. The default -0.5 with sig_u = 1 gives \(E[u] = 1\).
Weibull shape behind y_pcs_wb, which targets sfm(model_name = "NW"). The scale is sig_u.
Skew parameter \(\lambda\) behind y_pcs_tsl, which targets sfm(model_name = "TSL"). The scale is sig_u; \(\lambda \to 0\) recovers the exponential case.
David H. Bernstein
The function simulates two explanatory variables, \(x_1\) and \(x_2\), as transformations of uniform random variables.
The function generates several different frontier models by combining various distributions for \(u\) and \(v\):
**\(u\) Distributions (Inefficiency):** Half-Normal (HN), Truncated Normal (TN), Half-T (HT), Half-Cauchy (HC), Exponential (E), Half-Uniform (HU).
**\(v\) Distributions (Idiosyncratic):** Normal (N), t, Cauchy (C).
**Specific Model Outputs (y_pcs variants):**
y_pcs: Normal-Half Normal (N-HN): \(v \sim N(0, \sigma_v^2)\), \(u \sim |N(0, \sigma_u^2)|\).
y_pcs_z: N-HN with Heteroskedastic \(\sigma_u\): \(\sigma_{u,i} = \exp(0.9 + 0.6 Z_i)\), where \(Z\) is a uniform variable.
y_pcs_t: T-Half T (T-HT): \(v \sim T(\text{df}=a) \cdot \sigma_v\), \(u \sim |T(\text{df}=a)| \cdot \sigma_u\).
y_pcs_st: the column that actually matches sfm's THT. y_pcs_t above draws its two components as two independent rt() variates, which shares the degrees of freedom but not the mixing variable, so the composed error is not skew-t and THT cannot recover it. y_pcs_st uses the single common \(\lambda \sim \Gamma(a/2, a/2)\) of Tancredi (2002), i.e. \(y = h + (\epsilon - z)/\sqrt{\lambda}\). y_pcs_t is retained unchanged only for backward compatibility.
y_pcs_thn: Student's t--half normal, matching sfm's tHN: \(v \sim T(\text{df}=a) \cdot \sigma_v\) and \(u \sim |N(0,\sigma_u^2)|\), drawn independently. Heavy-tailed noise with a conventional one-sided term -- distinct from both y_pcs_t and y_pcs_st, in which the inefficiency is heavy-tailed too.
y_pcs_tn: Normal-Truncated Normal (N-TN): \(v \sim N(0, \sigma_v^2)\), \(u \sim TN(\mu, \sigma_u^2)\) on \([0, \infty)\).
y_pcs_e: Normal-Exponential (N-E): \(v \sim N(0, \sigma_v^2)\), \(u \sim Exp(\phi)\), where \(\phi = 1/\sigma_u\).
y_pcs_c: Cauchy-Half Cauchy (C-HC): \(v \sim Cauchy(0, \sigma_v)\), \(u \sim |Cauchy(0, \sigma_u)|\).
y_pcs_u: Normal-Half Uniform (N-HU): \(v \sim N(0, \sigma_v^2)\), \(u \sim U(0, \sigma_u)\).
y_pcs_w: Normal + Cauchy - Half Normal: \(v \sim N(0, \sigma_v^2) + Cauchy(0, \sigma_v)\), \(u \sim |N(0, \sigma_u^2)|\). This introduces a composite \(v\) term.
**Note:** The rtruncnorm function is required for y_pcs_tn and loads with the package. In isolation it could be loaded by using library(truncnorm).
# Generate 100 observations of SFA data
data_sfa <- data_gen_cs(
N = 100,
rand = 123,
sig_u = 0.5,
sig_v = 0.2,
cons = 5,
beta1 = 1.5,
beta2 = 2.0,
a = 5, # degrees of freedom for T/Half-T
mu = 0.1 # mean for Truncated Normal
)
# Display the first few rows of the generated data
head(data_sfa)
# Example of a Normal-Half Normal SFA model data
summary(data_sfa$y_pcs)
plot(density(data_sfa$y_pcs))
Run the code above in your browser using DataLab