library(plm)
library(wooldridge)
data("wagepan")
library(rmarkdown)
paged_table(wagepan)
library(plm)
wagepanpd <- pdata.frame(wagepan, index = c("nr", "year"))
pdim(wagepanpd)
## Balanced Panel: n = 545, T = 8, N = 4360
withinmodel1 <- plm(lwage ~ married + union + factor(year)*educ, data = wagepanpd, model = "within")
summary(withinmodel1)
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = lwage ~ married + union + factor(year) * educ, 
##     data = wagepanpd, model = "within")
## 
## Balanced Panel: n = 545, T = 8, N = 4360
## 
## Residuals:
##      Min.   1st Qu.    Median   3rd Qu.      Max. 
## -4.152111 -0.125630  0.010897  0.160800  1.483401 
## 
## Coefficients:
##                         Estimate Std. Error t-value  Pr(>|t|)    
## married                0.0548205  0.0184126  2.9773  0.002926 ** 
## union                  0.0829785  0.0194461  4.2671 2.029e-05 ***
## factor(year)1981      -0.0224158  0.1458885 -0.1537  0.877893    
## factor(year)1982      -0.0057611  0.1458558 -0.0395  0.968495    
## factor(year)1983       0.0104297  0.1458579  0.0715  0.942999    
## factor(year)1984       0.0843743  0.1458518  0.5785  0.562965    
## factor(year)1985       0.0497253  0.1458602  0.3409  0.733190    
## factor(year)1986       0.0656064  0.1458917  0.4497  0.652958    
## factor(year)1987       0.0904448  0.1458505  0.6201  0.535216    
## factor(year)1981:educ  0.0115854  0.0122625  0.9448  0.344827    
## factor(year)1982:educ  0.0147905  0.0122635  1.2061  0.227872    
## factor(year)1983:educ  0.0171182  0.0122633  1.3959  0.162830    
## factor(year)1984:educ  0.0165839  0.0122657  1.3521  0.176437    
## factor(year)1985:educ  0.0237085  0.0122738  1.9316  0.053479 .  
## factor(year)1986:educ  0.0274123  0.0122740  2.2334  0.025583 *  
## factor(year)1987:educ  0.0304332  0.0122723  2.4798  0.013188 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    572.05
## Residual Sum of Squares: 474.35
## R-Squared:      0.1708
## Adj. R-Squared: 0.048567
## F-statistic: 48.9069 on 16 and 3799 DF, p-value: < 2.22e-16
pvar(wagepanpd)
## no time variation:       nr black hisp educ 
## no individual variation: year d81 d82 d83 d84 d85 d86 d87
reg_ols <- plm(lwage ~ educ + black + hisp + exper + I(exper^2) + married + union + year, data = wagepanpd, model = "pooling")
reg_random <- plm(lwage ~ educ + black + hisp + exper + I(exper^2) + married + union + year, data = wagepanpd, model = "random")
reg_fe <- plm(lwage ~ educ + black + hisp + exper + I(exper^2) + married + union + year, data = wagepanpd, model = "within")
library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
stargazer(reg_ols, reg_random, reg_fe, type = "text", column.labels = c("OLS","RE","FE"))
## 
## ===========================================================================
##                                   Dependent variable:                      
##              --------------------------------------------------------------
##                                          lwage                             
##                         OLS                RE                FE            
##                         (1)               (2)                (3)           
## ---------------------------------------------------------------------------
## educ                 0.091***           0.092***                           
##                       (0.005)           (0.011)                            
##                                                                            
## black                -0.139***         -0.139***                           
##                       (0.024)           (0.048)                            
##                                                                            
## hisp                   0.016             0.022                             
##                       (0.021)           (0.043)                            
##                                                                            
## exper                0.067***           0.106***          0.132***         
##                       (0.014)           (0.015)            (0.010)         
##                                                                            
## I(exper2)            -0.002***         -0.005***          -0.005***        
##                       (0.001)           (0.001)            (0.001)         
##                                                                            
## married              0.108***           0.064***           0.047**         
##                       (0.016)           (0.017)            (0.018)         
##                                                                            
## union                0.182***           0.106***          0.080***         
##                       (0.017)           (0.018)            (0.019)         
##                                                                            
## year1981              0.058*             0.040              0.019          
##                       (0.030)           (0.025)            (0.020)         
##                                                                            
## year1982              0.063*             0.031             -0.011          
##                       (0.033)           (0.032)            (0.020)         
##                                                                            
## year1983              0.062*             0.020            -0.042**         
##                       (0.037)           (0.042)            (0.020)         
##                                                                            
## year1984              0.090**            0.043             -0.038*         
##                       (0.040)           (0.051)            (0.020)         
##                                                                            
## year1985              0.109**            0.058            -0.043**         
##                       (0.043)           (0.061)            (0.020)         
##                                                                            
## year1986             0.142***            0.092             -0.027          
##                       (0.046)           (0.071)            (0.020)         
##                                                                            
## year1987             0.174***            0.135*                            
##                       (0.049)           (0.081)                            
##                                                                            
## Constant               0.092             0.024                             
##                       (0.078)           (0.151)                            
##                                                                            
## ---------------------------------------------------------------------------
## Observations           4,360             4,360              4,360          
## R2                     0.189             0.181              0.181          
## Adjusted R2            0.187             0.178              0.061          
## F Statistic  72.459*** (df = 14; 4345) 957.774*** 83.851*** (df = 10; 3805)
## ===========================================================================
## Note:                                           *p<0.1; **p<0.05; ***p<0.01
phtest(reg_fe, reg_random)
## 
##  Hausman Test
## 
## data:  lwage ~ educ + black + hisp + exper + I(exper^2) + married +  ...
## chisq = 31.707, df = 10, p-value = 0.000448
## alternative hypothesis: one model is inconsistent