Exercise 7

Questions

7.1 Specify a random and a fixed effects model. Compare the results.

7.2 Execute the hausman test. Which model specification is more appropriate and why?

Data Prep

Stata


set more off
capt clear
version 14

use "_data/ex_mydf.dta", clear

. 
. set more off

. capt clear

. version 14

. 
. use "_data/ex_mydf.dta", clear
(PGEN: Feb 12, 2017 13:00:53-1 DBV32L)

R

Load Data

#### load dataset ####
ex_mydf <- readRDS(file = "_data/ex_mydf.rds")

asample <- ex_mydf %>% 
      filter(
            # Working Hours
            pgtatzeit >= 6,
            # age
            alter %>% dplyr::between(18, 65),
            # Employment Status
            pgemplst %in% c(1,2,4),   # full-time(1), part-time(2), marg.-empl(4)
            # population status
            pop <= 2, # only private households
            # restrict number of years
            syear > 2002) %>%
      # filter unplausible cases
      mutate(na = case_when(
              pid %in% c(1380202, 1380202, 607602, 2555301) ~ 1,
              pid == 8267202 & syear == 2007 ~ 1,
              pid == 2633801 & syear == 2006 ~ 1,
              pid == 2582901 & syear > 2006 ~ 1 )
             ) %>% 
      filter(is.na(na))

# Prepare Panel Dataset
p.asample <- pdata.frame(asample, index = c("pid", "syear"))

# information if panel dataframe
pdim(p.asample)
## Unbalanced Panel: n = 37989, T = 1-13, N = 167978
# summary(p.asample)

Answers

7.1

Specify a random and a fixed effects model. Compare the results.

Stata

use "_data/ex_mydf.dta", clear

xtset pid syear
* FE model
xtreg lnwage pgbilzeit c.erf##c.erf pgexpue ost frau i.pgallbet i.syear if asample==1 & syear>2002 ,   fe
est sto fixed

* RE model 
xtreg lnwage pgbilzeit c.erf##c.erf pgexpue ost frau i.pgallbet i.syear if asample==1 & syear>2002 ,  re 
est sto random

esttab fixed random

. use "_data/ex_mydf.dta", clear
(PGEN: Feb 12, 2017 13:00:53-1 DBV32L)

. 
. xtset pid syear
       panel variable:  pid (unbalanced)
        time variable:  syear, 1984 to 2015, but with gaps
                delta:  1 unit

. * FE model
. xtreg lnwage pgbilzeit c.erf##c.erf pgexpue ost frau i.pgallbet i.syear if as
> ample==1 & syear>2002 ,   fe
note: frau omitted because of collinearity

Fixed-effects (within) regression               Number of obs     =    156,029
Group variable: pid                             Number of groups  =     33,894

R-sq:                                           Obs per group:
     within  = 0.0401                                         min =          1
     between = 0.3541                                         avg =        4.6
     overall = 0.3156                                         max =         13

                                                F(21,122114)      =     242.73
corr(u_i, Xb)  = 0.1227                         Prob > F          =     0.0000

------------------------------------------------------------------------------
      lnwage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
   pgbilzeit |   .0529867   .0023403    22.64   0.000     .0483998    .0575736
         erf |    .045247   .0015267    29.64   0.000     .0422547    .0482393
             |
 c.erf#c.erf |  -.0006661   .0000183   -36.33   0.000     -.000702   -.0006301
             |
     pgexpue |  -.0332011   .0032925   -10.08   0.000    -.0396543   -.0267478
         ost |  -.1209915   .0138824    -8.72   0.000    -.1482008   -.0937822
        frau |          0  (omitted)
             |
    pgallbet |
[2] GE 20..  |   .0495245   .0038447    12.88   0.000      .041989    .0570599
[3] GE 20..  |   .0771106   .0044952    17.15   0.000     .0683001    .0859211
[4] GE 2000  |   .0896249    .004655    19.25   0.000     .0805012    .0987486
[5] Selbs..  |  -.0717673   .0070217   -10.22   0.000    -.0855298   -.0580048
             |
       syear |
       2004  |  -.0172732   .0041979    -4.11   0.000    -.0255011   -.0090453
       2005  |  -.0460263   .0046925    -9.81   0.000    -.0552235   -.0368291
       2006  |  -.0833928   .0052421   -15.91   0.000    -.0936673   -.0731183
       2007  |  -.1048617   .0058791   -17.84   0.000    -.1163846   -.0933387
       2008  |  -.1178463   .0066686   -17.67   0.000    -.1309167   -.1047759
       2009  |   -.109741   .0074812   -14.67   0.000    -.1244041    -.095078
       2010  |  -.1125573   .0082187   -13.70   0.000    -.1286657   -.0964488
       2011  |  -.1263725   .0090593   -13.95   0.000    -.1441287   -.1086164
       2012  |  -.1278882   .0099357   -12.87   0.000    -.1473619   -.1084144
       2013  |  -.1120904   .0106497   -10.53   0.000    -.1329637   -.0912171
       2014  |  -.0969339   .0114189    -8.49   0.000    -.1193146   -.0745531
       2015  |  -.0739467   .0123574    -5.98   0.000     -.098167   -.0497265
             |
       _cons |   1.564629   .0348093    44.95   0.000     1.496403    1.632854
-------------+----------------------------------------------------------------
     sigma_u |  .48874503
     sigma_e |  .28535324
         rho |  .74577917   (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(33893, 122114) = 8.99               Prob > F = 0.0000

. est sto fixed

. 
. * RE model 
. xtreg lnwage pgbilzeit c.erf##c.erf pgexpue ost frau i.pgallbet i.syear if as
> ample==1 & syear>2002 ,  re 

Random-effects GLS regression                   Number of obs     =    156,029
Group variable: pid                             Number of groups  =     33,894

R-sq:                                           Obs per group:
     within  = 0.0369                                         min =          1
     between = 0.4279                                         avg =        4.6
     overall = 0.3879                                         max =         13

                                                Wald chi2(23)     =          .
corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =          .

------------------------------------------------------------------------------
      lnwage |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
   pgbilzeit |   .0802379   .0008554    93.81   0.000     .0785614    .0819144
         erf |   .0396457    .000537    73.83   0.000     .0385932    .0406982
             |
 c.erf#c.erf |  -.0006464   .0000129   -50.00   0.000    -.0006717    -.000621
             |
     pgexpue |    -.05377   .0012146   -44.27   0.000    -.0561506   -.0513894
         ost |  -.2602876   .0057363   -45.38   0.000    -.2715306   -.2490446
        frau |  -.1655567   .0050538   -32.76   0.000    -.1754619   -.1556514
             |
    pgallbet |
[2] GE 20..  |   .0832469   .0033899    24.56   0.000     .0766028    .0898909
[3] GE 20..  |   .1399706   .0038861    36.02   0.000     .1323539    .1475873
[4] GE 2000  |   .1697413   .0039608    42.85   0.000     .1619782    .1775044
[5] Selbs..  |  -.0827156   .0063581   -13.01   0.000    -.0951774   -.0702539
             |
       syear |
       1984  |          0  (empty)
       1985  |          0  (empty)
       1986  |          0  (empty)
       1987  |          0  (empty)
       1988  |          0  (empty)
       1989  |          0  (empty)
       1990  |          0  (empty)
       1991  |          0  (empty)
       1992  |          0  (empty)
       1993  |          0  (empty)
       1994  |          0  (empty)
       1995  |          0  (empty)
       1996  |          0  (empty)
       1997  |          0  (empty)
       1998  |          0  (empty)
       1999  |          0  (empty)
       2000  |          0  (empty)
       2001  |          0  (empty)
       2002  |          0  (empty)
       2003  |   1.336591   .0125562   106.45   0.000     1.311981    1.361201
       2004  |   1.321806   .0125879   105.01   0.000     1.297134    1.346478
       2005  |   1.296002   .0126865   102.16   0.000     1.271137    1.320867
       2006  |   1.261972   .0127316    99.12   0.000     1.237018    1.286925
       2007  |   1.243458   .0127611    97.44   0.000     1.218447    1.268469
       2008  |    1.23416   .0128557    96.00   0.000     1.208964    1.259357
       2009  |   1.245013   .0129041    96.48   0.000     1.219722    1.270305
       2010  |   1.243918   .0128664    96.68   0.000     1.218701    1.269136
       2011  |   1.233039   .0128811    95.72   0.000     1.207793    1.258286
       2012  |   1.231218   .0129403    95.15   0.000     1.205856    1.256581
       2013  |   1.251511   .0128542    97.36   0.000     1.226317    1.276705
       2014  |   1.264077   .0130704    96.71   0.000      1.23846    1.289695
       2015  |   1.289241    .013119    98.27   0.000     1.263528    1.314953
             |
       _cons |          0  (omitted)
-------------+----------------------------------------------------------------
     sigma_u |  .41250016
     sigma_e |  .28535324
         rho |  .67634333   (fraction of variance due to u_i)
------------------------------------------------------------------------------

. est sto random

. 
. esttab fixed random

--------------------------------------------
                      (1)             (2)   
                   lnwage          lnwage   
--------------------------------------------
pgbilzeit          0.0530***       0.0802***
                  (22.64)         (93.81)   

erf                0.0452***       0.0396***
                  (29.64)         (73.83)   

c.erf#c.erf     -0.000666***    -0.000646***
                 (-36.33)        (-50.00)   

pgexpue           -0.0332***      -0.0538***
                 (-10.08)        (-44.27)   

ost                -0.121***       -0.260***
                  (-8.72)        (-45.38)   

frau                    0          -0.166***
                      (.)        (-32.76)   

1.pgallbet              0               0   
                      (.)             (.)   

2.pgallbet         0.0495***       0.0832***
                  (12.88)         (24.56)   

3.pgallbet         0.0771***        0.140***
                  (17.15)         (36.02)   

4.pgallbet         0.0896***        0.170***
                  (19.25)         (42.85)   

5.pgallbet        -0.0718***      -0.0827***
                 (-10.22)        (-13.01)   

2003.syear              0           1.337***
                      (.)        (106.45)   

2004.syear        -0.0173***        1.322***
                  (-4.11)        (105.01)   

2005.syear        -0.0460***        1.296***
                  (-9.81)        (102.16)   

2006.syear        -0.0834***        1.262***
                 (-15.91)         (99.12)   

2007.syear         -0.105***        1.243***
                 (-17.84)         (97.44)   

2008.syear         -0.118***        1.234***
                 (-17.67)         (96.00)   

2009.syear         -0.110***        1.245***
                 (-14.67)         (96.48)   

2010.syear         -0.113***        1.244***
                 (-13.70)         (96.68)   

2011.syear         -0.126***        1.233***
                 (-13.95)         (95.72)   

2012.syear         -0.128***        1.231***
                 (-12.87)         (95.15)   

2013.syear         -0.112***        1.252***
                 (-10.53)         (97.36)   

2014.syear        -0.0969***        1.264***
                  (-8.49)         (96.71)   

2015.syear        -0.0739***        1.289***
                  (-5.98)         (98.27)   

1984.syear                              0   
                                      (.)   

1985.syear                              0   
                                      (.)   

1986.syear                              0   
                                      (.)   

1987.syear                              0   
                                      (.)   

1988.syear                              0   
                                      (.)   

1989.syear                              0   
                                      (.)   

1990.syear                              0   
                                      (.)   

1991.syear                              0   
                                      (.)   

1992.syear                              0   
                                      (.)   

1993.syear                              0   
                                      (.)   

1994.syear                              0   
                                      (.)   

1995.syear                              0   
                                      (.)   

1996.syear                              0   
                                      (.)   

1997.syear                              0   
                                      (.)   

1998.syear                              0   
                                      (.)   

1999.syear                              0   
                                      (.)   

2000.syear                              0   
                                      (.)   

2001.syear                              0   
                                      (.)   

2002.syear                              0   
                                      (.)   

_cons               1.565***            0   
                  (44.95)             (.)   
--------------------------------------------
N                  156029          156029   
--------------------------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001

R

Model

Fixed Effects Model

# FE Model
fixed   <- p.asample %>% 
      plm(lnwage ~  pgbilzeit + erf + I(erf^2) + pgexpue + ost + pgallbet + syear,
             data = ., 
             model = "within" 
             # weights = phrf
             )

tidy(fixed$coefficients[1:30])

Random Model

# RE Model
random  <- plm(lnwage ~  pgbilzeit + erf + I(erf^2) + pgexpue + ost + pgallbet + syear,
             data = p.asample, 
             model = "random" 
             # weights = phrf
             )

tidy(random)
Plot

7.2

Execute the hausman test. Which model specification is more appropriate and why?

Stata

use "_data/ex_mydf.dta", clear

xtreg lnwage pgbilzeit c.erf##c.erf pgexpue ost frau i.pgallbet i.syear if asample==1 & syear>2002 ,   fe
estimates store fixed

xtreg lnwage pgbilzeit c.erf##c.erf pgexpue ost frau i.pgallbet i.syear if asample==1 & syear>2002 ,  re 
estimates store random

hausman fixed random

. use "_data/ex_mydf.dta", clear
(PGEN: Feb 12, 2017 13:00:53-1 DBV32L)

. 
. xtreg lnwage pgbilzeit c.erf##c.erf pgexpue ost frau i.pgallbet i.syear if as
> ample==1 & syear>2002 ,   fe
must specify panelvar; use xtset
r(459);

end of do-file
r(459);

R

Test
# Hausman Test
hausman <- phtest(fixed, random)

hausman
## 
##  Hausman Test
## 
## data:  lnwage ~ pgbilzeit + erf + I(erf^2) + pgexpue + ost + pgallbet +  ...
## chisq = 2000, df = 20, p-value <2e-16
## alternative hypothesis: one model is inconsistent
More Info

other things

pvar(p.asample)
## no time variation:       psample sex gebjahr pid cid pgpbbilo pgbilztev frau na 
## no individual variation: syear pgerljob pgbetr pgoeffd pgausb pgpartnr pgpsbil pgpbbil01 pgpbbil02 pgpbbil03 pgpsbila pgpbbila pgpsbilo pgpbbilo pgfamstd pgbilzeit pgerwzeit pgvebzeit pguebstd pgisco88 pgisei88 pgmps92 pgnace pgsiops88 pgegp88 pgkldb92 pgautono pgisced97 pgcasmin pgstib pgallbet pgexpft pgexppt pgexpue pgfield pgdegree pgtraina pgtrainb pgtrainc pgtraind pgfdt_f pgbilztch pgbilztev pgsndjob pgimpsnd pgjobend pgkldb10 pgisco08 pgisced11 cpi adj_fac2010 adj_fac2015 cpi_s lnwage erf erfq qualstand intern cpgbilzeit cerf na 
## all NA in time dimension for at least one individual:  pgerljob pgbetr pgoeffd pgausb pgpartz pgpartnr pgnation pgpsbil pgpbbil01 pgpbbil02 pgpbbil03 pgpsbila pgpbbila pgpsbilo pgpbbilo pgfamstd pgbilzeit pgerwzeit pgvebzeit pguebstd pgisco88 pgisei88 pgmps92 pgnace pgsiops88 pgegp88 pgkldb92 pgautono pgisced97 pgcasmin pgstib pgallbet pgexpft pgexppt pgexpue pgfield pgdegree pgtraina pgtrainb pgtrainc pgtraind pgfdt_f pgbilztch pgbilztev pgsndjob pgimpsnd pgjobend pgkldb10 pgisco08 pgisced11 lnwage erf erfq qualstand intern cpgbilzeit cerf na 
## all NA in ind. dimension for at least one time period: pgerljob pgbetr pgoeffd pgausb pgpartz pgpartnr pgnation pgpsbil pgpbbil01 pgpbbil02 pgpbbil03 pgpsbila pgpbbila pgpsbilo pgpbbilo pgfamstd pgbilzeit pgerwzeit pgvebzeit pguebstd pgisco88 pgisei88 pgmps92 pgnace pgsiops88 pgegp88 pgkldb92 pgautono pgisced97 pgcasmin pgstib pgallbet pgexpft pgexppt pgexpue pgfield pgdegree pgtraina pgtrainb pgtrainc pgtraind pgfdt_f pgbilztch pgbilztev pgsndjob pgimpsnd pgjobend pgkldb10 pgisco08 pgisced11 lnwage erf erfq qualstand intern cpgbilzeit cerf na