library(wooldridge)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
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
# Load the data
data("minwage")
# Create lagged variables
minwage <- minwage %>%
  mutate(gwage232_lag1 = lag(gwage232, 1),
         gemp232_lag1 = lag(gemp232, 1))
# Handle missing values (e.g., by removing rows with missing values)
minwage <- na.omit(minwage)
# (i) First-order autocorrelation
acf(minwage$gwage232, lag.max = 1)

# (ii) Dynamic model estimation
model1 <- lm(gwage232 ~ gwage232_lag1 + gmwage + gcpi, data = minwage)
summary(model1)
## 
## Call:
## lm(formula = gwage232 ~ gwage232_lag1 + gmwage + gcpi, data = minwage)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.044649 -0.004114 -0.001262  0.004481  0.041568 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    0.0023648  0.0004295   5.506 5.45e-08 ***
## gwage232_lag1 -0.0684816  0.0343986  -1.991   0.0470 *  
## gmwage         0.1517511  0.0095115  15.955  < 2e-16 ***
## gcpi           0.2586795  0.0858602   3.013   0.0027 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.007775 on 595 degrees of freedom
## Multiple R-squared:  0.3068, Adjusted R-squared:  0.3033 
## F-statistic: 87.79 on 3 and 595 DF,  p-value: < 2.2e-16
# (iii) Adding lagged employment
model2 <- lm(gwage232 ~ gwage232_lag1 + gmwage + gcpi + gemp232_lag1, data = minwage)
summary(model2)
## 
## Call:
## lm(formula = gwage232 ~ gwage232_lag1 + gmwage + gcpi + gemp232_lag1, 
##     data = minwage)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.043900 -0.004316 -0.000955  0.004255  0.042430 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    0.0023960  0.0004254   5.633 2.74e-08 ***
## gwage232_lag1 -0.0656875  0.0340720  -1.928 0.054344 .  
## gmwage         0.1525470  0.0094213  16.192  < 2e-16 ***
## gcpi           0.2536899  0.0850342   2.983 0.002968 ** 
## gemp232_lag1   0.0606620  0.0169691   3.575 0.000379 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.007699 on 594 degrees of freedom
## Multiple R-squared:  0.3214, Adjusted R-squared:  0.3169 
## F-statistic: 70.34 on 4 and 594 DF,  p-value: < 2.2e-16
# (iv) Comparing models
stargazer(model1, model2, type = "text")
## 
## ===================================================================
##                                   Dependent variable:              
##                     -----------------------------------------------
##                                        gwage232                    
##                               (1)                     (2)          
## -------------------------------------------------------------------
## gwage232_lag1              -0.068**                 -0.066*        
##                             (0.034)                 (0.034)        
##                                                                    
## gmwage                     0.152***                0.153***        
##                             (0.010)                 (0.009)        
##                                                                    
## gcpi                       0.259***                0.254***        
##                             (0.086)                 (0.085)        
##                                                                    
## gemp232_lag1                                       0.061***        
##                                                     (0.017)        
##                                                                    
## Constant                   0.002***                0.002***        
##                            (0.0004)                (0.0004)        
##                                                                    
## -------------------------------------------------------------------
## Observations                  599                     599          
## R2                           0.307                   0.321         
## Adjusted R2                  0.303                   0.317         
## Residual Std. Error    0.008 (df = 595)        0.008 (df = 594)    
## F Statistic         87.792*** (df = 3; 595) 70.343*** (df = 4; 594)
## ===================================================================
## Note:                                   *p<0.1; **p<0.05; ***p<0.01
# (v) Regression of gmwage on lagged variables
model3 <- lm(gmwage ~ gwage232_lag1 + gemp232_lag1, data = minwage)
summary(model3)
## 
## Call:
## lm(formula = gmwage ~ gwage232_lag1 + gemp232_lag1, data = minwage)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.01987 -0.00511 -0.00385 -0.00290  0.62191 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)  
## (Intercept)    0.003487   0.001465   2.380   0.0176 *
## gwage232_lag1  0.212051   0.146727   1.445   0.1489  
## gemp232_lag1  -0.042776   0.073749  -0.580   0.5621  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.03347 on 596 degrees of freedom
## Multiple R-squared:  0.004117,   Adjusted R-squared:  0.0007754 
## F-statistic: 1.232 on 2 and 596 DF,  p-value: 0.2924

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.