require( npsf )
# Load Penn World Tables 5.6 dataset
data( pwt56 )
head( pwt56 )
# Create some missing values
pwt56 [4, "K"] <- NA
# Stochastic production frontier model with
# homoskedastic error components (half-normal)
# Use subset of observations - for year 1965
m1 <- sf(log(Y) ~ log(L) + log(K), data = pwt56,
subset = year == 1965, distribution = "h")
# Write efficiencies to the data frame using 'esample':
pwt56$BC[ m1$esample ] <- m1$efficiencies$BC
View(pwt56)
# Computation using matrices
Y1 <- as.matrix(log(pwt56[pwt56$year == 1965,
c("Y"), drop = FALSE]))
X1 <- as.matrix(log(pwt56[pwt56$year == 1965,
c("K", "L"), drop = FALSE]))
X1 [51, 2] <- NA # create missing
X1 [49, 1] <- NA # create missing
m2 <- sf(Y1 ~ X1, distribution = "h")
# Load U.S. commercial banks dataset
data(banks05)
head(banks05)
# Doubly heteroskedastic stochastic cost frontier
# model (truncated normal)
# Print summaries of cost efficiencies' estimates
m3 <- sf(lnC ~ lnw1 + lnw2 + lny1 + lny2, uhet = ~ ER,
vhet = ~ LA, data = banks05, distribution = "t",
prod = FALSE, print.level = 3)
# Non-monotonic marginal effects of equity ratio on
# the mean of distribution of inefficiency term
m4 <- sf(lnC ~ lnw1 + lnw2 + lny1 + lny2, uhet = ~ ER,
tmean = ~ ER, data = banks05, distribution = "t",
prod = FALSE, marg.eff = TRUE)
summary(m4$marg.effects)
Run the code above in your browser using DataLab