Running examples in ‘sampleSelection-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: selection
> ### Title: Heckman-style selection and treatment effect models
> ### Aliases: selection heckit treatReg
> ### Keywords: models regression
> 
> ### ** Examples
> 
> ## Greene( 2003 ): example 22.8, page 786
> data( Mroz87 )
> Mroz87$kids  <- ( Mroz87$kids5 + Mroz87$kids618 > 0 )
> # Two-step estimation
> summary( heckit( lfp ~ age + I( age^2 ) + faminc + kids + educ,
+    wage ~ exper + I( exper^2 ) + educ + city, Mroz87 ) )
--------------------------------------------
Tobit 2 model (sample selection model)
2-step Heckman / heckit estimation
753 observations (325 censored and 428 observed)
14 free parameters (df = 740)
Probit selection equation:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -4.157e+00  1.402e+00  -2.965 0.003127 ** 
age          1.854e-01  6.597e-02   2.810 0.005078 ** 
I(age^2)    -2.426e-03  7.735e-04  -3.136 0.001780 ** 
faminc       4.580e-06  4.206e-06   1.089 0.276544    
kidsTRUE    -4.490e-01  1.309e-01  -3.430 0.000638 ***
educ         9.818e-02  2.298e-02   4.272 2.19e-05 ***
Outcome equation:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.9712003  2.0593505  -0.472    0.637    
exper        0.0210610  0.0624646   0.337    0.736    
I(exper^2)   0.0001371  0.0018782   0.073    0.942    
educ         0.4170174  0.1002497   4.160 3.56e-05 ***
city         0.4438379  0.3158984   1.405    0.160    
Multiple R-Squared:0.1264,	Adjusted R-Squared:0.116
   Error terms:
              Estimate Std. Error t value Pr(>|t|)
invMillsRatio   -1.098      1.266  -0.867    0.386
sigma            3.200         NA      NA       NA
rho             -0.343         NA      NA       NA
--------------------------------------------
> # ML estimation
> summary( selection( lfp ~ age + I( age^2 ) + faminc + kids + educ,
+    wage ~ exper + I( exper^2 ) + educ + city, Mroz87 ) )
--------------------------------------------
Tobit 2 model (sample selection model)
Maximum Likelihood estimation
Newton-Raphson maximisation, 5 iterations
Return code 2: successive function values within tolerance limit
Log-Likelihood: -1581.258 
753 observations (325 censored and 428 observed)
13 free parameters (df = 740)
Probit selection equation:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -4.120e+00  1.401e+00  -2.942 0.003368 ** 
age          1.840e-01  6.587e-02   2.794 0.005345 ** 
I(age^2)    -2.409e-03  7.723e-04  -3.119 0.001886 ** 
faminc       5.680e-06  4.416e-06   1.286 0.198782    
kidsTRUE    -4.506e-01  1.302e-01  -3.461 0.000568 ***
educ         9.528e-02  2.315e-02   4.115  4.3e-05 ***
Outcome equation:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -1.9630242  1.1982209  -1.638    0.102    
exper        0.0278683  0.0615514   0.453    0.651    
I(exper^2)  -0.0001039  0.0018388  -0.056    0.955    
educ         0.4570051  0.0732299   6.241 7.33e-10 ***
city         0.4465290  0.3159209   1.413    0.158    
   Error terms:
      Estimate Std. Error t value Pr(>|t|)    
sigma   3.1084     0.1138  27.307   <2e-16 ***
rho    -0.1320     0.1651  -0.799    0.424    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
--------------------------------------------
> 
> ## Example using binary outcome for selection model.
> ## We estimate the probability of womens' education on their
> ## chances to get high wage (> $5/hr in 1975 USD), using PSID data
> ## We use education as explanatory variable
> ## and add age, kids, and non-work income as exclusion restrictions.
> data(Mroz87)
> m <- selection(lfp ~ educ + age + kids5 + kids618 + nwifeinc,
+    wage >= 5 ~ educ, data = Mroz87 )
> summary(m)
--------------------------------------------
Tobit 2 model with binary outcome (sample selection model)
Maximum Likelihood estimation
BHHH maximisation, 8 iterations
Return code 2: successive function values within tolerance limit
Log-Likelihood: -653.2037 
753 observations (325 censored and 428 observed)
9 free parameters (df = 744)
Probit selection equation:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.430362   0.475966   0.904    0.366    
educ         0.156223   0.023811   6.561 1.00e-10 ***
age         -0.034713   0.007649  -4.538 6.61e-06 ***
kids5       -0.890560   0.112663  -7.905 9.69e-15 ***
kids618     -0.038167   0.039320  -0.971    0.332    
nwifeinc    -0.020948   0.004318  -4.851 1.49e-06 ***
Outcome equation:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  -4.5213     0.5611  -8.058 3.08e-15 ***
educ          0.2879     0.0369   7.800 2.09e-14 ***
   Error terms:
    Estimate Std. Error t value Pr(>|t|)
rho   0.1164     0.2706    0.43    0.667
--------------------------------------------
> 
> 
> ## example using random numbers
> library( "mvtnorm" )
> nObs <- 1000
> sigma <- matrix( c( 1, -0.7, -0.7, 1 ), ncol = 2 )
> errorTerms <- rmvnorm( nObs, c( 0, 0 ), sigma )
> myData <- data.frame( no = c( 1:nObs ), x1 = rnorm( nObs ), x2 = rnorm( nObs ),
+    u1 = errorTerms[ , 1 ], u2 =  errorTerms[ , 2 ] )
> myData$y <- 2 + myData$x1 + myData$u1
> myData$s <- ( 2 * myData$x1 + myData$x2 + myData$u2 - 0.2 ) > 0
> myData$y[ !myData$s ] <- NA
> myOls <- lm( y ~ x1, data = myData)
> summary( myOls )

Call:
lm(formula = y ~ x1, data = myData)

Residuals:
    Min      1Q  Median      3Q     Max 
-3.1670 -0.6422 -0.0176  0.6851  3.1186 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  1.53676    0.06236   24.64   <2e-16 ***
x1           1.26069    0.05891   21.40   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.9922 on 472 degrees of freedom
  (526 observations deleted due to missingness)
Multiple R-squared:  0.4925,	Adjusted R-squared:  0.4914 
F-statistic:   458 on 1 and 472 DF,  p-value: < 2.2e-16

> myHeckit <- heckit( s ~ x1 + x2, y ~ x1, myData, print.level = 1 )
Tobit 2 model
> summary( myHeckit )
--------------------------------------------
Tobit 2 model (sample selection model)
2-step Heckman / heckit estimation
1000 observations (526 censored and 474 observed)
8 free parameters (df = 993)
Probit selection equation:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.22904    0.06106  -3.751 0.000186 ***
x1           1.97384    0.12229  16.141  < 2e-16 ***
x2           1.01003    0.07930  12.737  < 2e-16 ***
Outcome equation:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  2.12355    0.10883   19.51   <2e-16 ***
x1           0.89186    0.08257   10.80   <2e-16 ***
Multiple R-Squared:0.5404,	Adjusted R-Squared:0.5385
   Error terms:
              Estimate Std. Error t value Pr(>|t|)    
invMillsRatio  -0.9622     0.1318  -7.298 5.99e-13 ***
sigma           1.0750         NA      NA       NA    
rho            -0.8950         NA      NA       NA    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
--------------------------------------------
> 
> ## example using random numbers with IV/2SLS estimation
> library( "mvtnorm" )
> nObs <- 1000
> sigma <- matrix( c( 1, 0.5, 0.1, 0.5, 1, -0.3, 0.1, -0.3, 1 ), ncol = 3 )
> errorTerms <- rmvnorm( nObs, c( 0, 0, 0 ), sigma )
> myData <- data.frame( no = c( 1:nObs ), x1 = rnorm( nObs ), x2 = rnorm( nObs ),
+    u1 = errorTerms[ , 1 ], u2 = errorTerms[ , 2 ], u3 = errorTerms[ , 3 ] )
> myData$w <- 1 + myData$x1 + myData$u1
> myData$y <- 2 + myData$w + myData$u2
> myData$s <- ( 2 * myData$x1 + myData$x2 + myData$u3 - 0.2 ) > 0
> myData$y[ !myData$s ] <- NA
> myHeckit <- heckit( s ~ x1 + x2, y ~ w, data = myData )
> summary( myHeckit )  # biased!
--------------------------------------------
Tobit 2 model (sample selection model)
2-step Heckman / heckit estimation
1000 observations (527 censored and 473 observed)
8 free parameters (df = 993)
Probit selection equation:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.15979    0.05860  -2.727  0.00651 ** 
x1           1.86891    0.11381  16.421  < 2e-16 ***
x2           0.98799    0.07971  12.394  < 2e-16 ***
Outcome equation:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  1.08092    0.09163   11.80   <2e-16 ***
w            1.45660    0.03713   39.23   <2e-16 ***
Multiple R-Squared:0.7841,	Adjusted R-Squared:0.7832
   Error terms:
              Estimate Std. Error t value Pr(>|t|)  
invMillsRatio   0.1829     0.1013   1.806   0.0713 .
sigma           0.9215         NA      NA       NA  
rho             0.1984         NA      NA       NA  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
--------------------------------------------
> myHeckitIv <- heckit( s ~ x1 + x2, y ~ w, data = myData, inst = ~ x1 )
> summary( myHeckitIv ) # unbiased
--------------------------------------------
Tobit 2 model (sample selection model)
2-step Heckman / heckit estimation
1000 observations (527 censored and 473 observed)
8 free parameters (df = 993)
Probit selection equation:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.15979    0.05860  -2.727  0.00651 ** 
x1           1.86891    0.11381  16.421  < 2e-16 ***
x2           0.98799    0.07971  12.394  < 2e-16 ***
Outcome equation:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   2.0345     0.1067   19.07   <2e-16 ***
w             0.9785     0.0432   22.65   <2e-16 ***
Multiple R-Squared:0.7083,	Adjusted R-Squared:0.707
   Error terms:
              Estimate Std. Error t value Pr(>|t|)  
invMillsRatio  -0.2891     0.1175   -2.46   0.0141 *
sigma           1.0767         NA      NA       NA  
rho            -0.2685         NA      NA       NA  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
--------------------------------------------
> 
> ## tobit-5 example
> N <- 500
>    library(mvtnorm)
>    vc <- diag(3)
>    vc[lower.tri(vc)] <- c(0.9, 0.5, 0.6)
>    vc[upper.tri(vc)] <- vc[lower.tri(vc)]
>    eps <- rmvnorm(N, rep(0, 3), vc)
>    xs <- runif(N)
>    ys <- xs + eps[,1] > 0
>    xo1 <- runif(N)
>    yo1 <- xo1 + eps[,2]
>    xo2 <- runif(N)
>    yo2 <- xo2 + eps[,3]
>    a <- selection(ys~xs, list(yo1 ~ xo1, yo2 ~ xo2))
>    summary(a)
--------------------------------------------
Tobit 5 model (switching regression model)
Maximum Likelihood estimation
Newton-Raphson maximisation, 5 iterations
Return code 1: gradient close to zero
Log-Likelihood: -916.9684 
500 observations: 157 selection 1 (FALSE) and 343 selection 2 (TRUE)
10 free parameters (df = 490)
Probit selection equation:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  -0.0534     0.1065  -0.501    0.616    
xs            1.1250     0.1842   6.106 2.08e-09 ***
Outcome equation 1:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.07615    0.18201   0.418    0.676    
xo1          0.92591    0.17272   5.361 1.28e-07 ***
Outcome equation 2:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.01079    0.17850  -0.060    0.952    
xo2          1.09098    0.17267   6.318 5.95e-10 ***
   Error terms:
       Estimate Std. Error t value Pr(>|t|)    
sigma1  0.97959    0.10528   9.305   <2e-16 ***
sigma2  0.97087    0.06317  15.370   <2e-16 ***
rho1    0.88349    0.05759  15.341   <2e-16 ***
rho2    0.34270    0.30009   1.142    0.254    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
--------------------------------------------
> 
> ## tobit2 example
>    vc <- diag(2)
>    vc[2,1] <- vc[1,2] <- -0.7
>    eps <- rmvnorm(N, rep(0, 2), vc)
>    xs <- runif(N)
>    ys <- xs + eps[,1] > 0
>    xo <- runif(N)
>    yo <- (xo + eps[,2])*(ys > 0)
>    a <- selection(ys~xs, yo ~xo)
>    summary(a)
--------------------------------------------
Tobit 2 model (sample selection model)
Maximum Likelihood estimation
Newton-Raphson maximisation, 3 iterations
Return code 2: successive function values within tolerance limit
Log-Likelihood: -725.3648 
500 observations (160 censored and 340 observed)
6 free parameters (df = 494)
Probit selection equation:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   0.1222     0.1095   1.115 0.265198    
xs            0.7149     0.1955   3.657 0.000283 ***
Outcome equation:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.01516    0.15424  -0.098    0.922    
xo           0.87447    0.15769   5.545 4.78e-08 ***
   Error terms:
      Estimate Std. Error t value Pr(>|t|)    
sigma  0.91843    0.08754  10.492  < 2e-16 ***
rho   -0.60686    0.22383  -2.711  0.00694 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
--------------------------------------------
> 
> ## Example for treatment regressions
> ## Estimate the effect of treatment on income
> ## selection outcome: treatment participation, logical (treatment)
> ## selection explanatory variables: age, education (years)
> ##   unemployment in 1974, 1975, race
> ## outcome: log real income 1978
> ## outcome explanatory variables: treatment, age, education, race.
> ## unemployment variables are treated as exclusion restriction
> data(Treatment, package="Ecdat")
Error in find.package(package, lib.loc, verbose = verbose) : 
  there is no package called ‘Ecdat’
Calls: data -> find.package
Execution halted