Last updated: 2020-12-28

Checks: 6 1

Knit directory: R-Guide/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20201221) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 97b8329. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .RData
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/

Unstaged changes:
    Modified:   analysis/q_8731_hw3.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/q_8731_hw3.Rmd) and HTML (docs/q_8731_hw3.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 97b8329 KaranSShakya 2020-12-28 8731 qt 2
html 97b8329 KaranSShakya 2020-12-28 8731 qt 2
Rmd bd2489c KaranSShakya 2020-12-27 8731 q1 half solved
html bd2489c KaranSShakya 2020-12-27 8731 q1 half solved
Rmd b07f4c3 KaranSShakya 2020-12-27 econometrics problems page + data
html b07f4c3 KaranSShakya 2020-12-27 econometrics problems page + data

1 Lagged Regression

Dataset is:

# A tibble: 2 x 5
    Obs  Year Quarter Income Consumption
  <dbl> <dbl>   <dbl>  <dbl>       <dbl>
1     1  1947       1 59505        57168
2     2  1947       2 59717.       55464

\(c_t\) is log of consumption, \(y_t\) is log of income. Their first differences are \(\Delta c_t = c_t - c_{t-1}\) and \(\Delta y_t = y_t - y_{t-1}\).

The model for the period 1953:1 to 1996:4, \[ \Delta c_t = \beta_1 + \beta_2 \Delta y_t + \beta_3 \Delta y_{t-1} + \beta_4 \Delta y_{t-2} + \beta_5 \Delta y_{t-3} + \beta_6 \Delta y_{t-4} \] ## Estimation Let \(\gamma = \sum_{l=2}^{6} \beta_l\). Calculate \(\hat{\gamma}\) and its SE.

consumption1 <- consumption %>% 
  mutate(ct = log(Consumption), yt=log(Income),
         del_ct = ct-lag(ct),
         del_yt = yt-lag(yt),
         yt1 = lag(yt, 1),
         yt2 = lag(yt, 2),
         yt3 = lag(yt, 3),
         yt4 = lag(yt, 4),
         del_yt1 = yt1-lag(yt1),
         del_yt2 = yt2-lag(yt2),
         del_yt3 = yt3-lag(yt3),
         del_yt4 = yt4-lag(yt4),
         ct1 = lag(ct, 1)) #adding new variables 

cons1 <- consumption1 %>% 
  filter(Year >= 1953 & Year <= 1996)

cons1.model <- lm(del_ct ~ del_yt+del_yt1+del_yt2+del_yt3+del_yt4, data=cons1)
summ(cons1.model, digits = 4)
MODEL INFO:
Observations: 176
Dependent Variable: del_ct
Type: OLS linear regression 

MODEL FIT:
F(5,170) = 10.6489, p = 0.0000
R² = 0.2385
Adj. R² = 0.2161 

Standard errors: OLS
-------------------------------------------------------
                       Est.     S.E.    t val.        p
----------------- --------- -------- --------- --------
(Intercept)          0.0051   0.0012    4.3589   0.0000
del_yt               0.3058   0.0545    5.6117   0.0000
del_yt1              0.1242   0.0544    2.2813   0.0238
del_yt2              0.0425   0.0551    0.7724   0.4410
del_yt3              0.1239   0.0545    2.2730   0.0243
del_yt4             -0.1233   0.0539   -2.2883   0.0234
-------------------------------------------------------
gamma_h <- cons1.model$coefficients[2]+cons1.model$coefficients[3]+
  cons1.model$coefficients[4]+cons1.model$coefficients[5]+
  cons1.model$coefficients[6]
kable(gamma_h, row.names = F, align = "l")
x
0.4731631

2 Hypothesis Tests

The dataset is as follows:

# A tibble: 5 x 4
    Obs   Dep    X_2    X_3
  <dbl> <dbl>  <dbl>  <dbl>
1     1  2.75 0.0121 0.0365
2     2  8.23 1.69   3.74  
3     3  6.70 0.404  2.31  
4     4  7.28 0.606  1.62  
5     5  7.64 2.11   6.95  

Classical linear regression model, \[ \begin{align} y = \beta_1 + \beta_2 x_2 + \beta_3 x_3 + u, && u \sim N (0, \sigma^2 I) \end{align} \]

model.class <- lm(Dep~X_2+X_3, data = classical)
summ(model.class, digits = 4)
MODEL INFO:
Observations: 50
Dependent Variable: Dep
Type: OLS linear regression 

MODEL FIT:
F(2,47) = 68.1609, p = 0.0000
R² = 0.7436
Adj. R² = 0.7327 

Standard errors: OLS
------------------------------------------------------
                      Est.     S.E.    t val.        p
----------------- -------- -------- --------- --------
(Intercept)         5.0949   0.1976   25.7815   0.0000
X_2                 1.1349   0.1408    8.0583   0.0000
X_3                 0.2221   0.0945    2.3487   0.0231
------------------------------------------------------

test \(\beta_3 = 0\)

linearHypothesis(model.class, "X_3 = 0")
Linear hypothesis test

Hypothesis:
X_3 = 0

Model 1: restricted model
Model 2: Dep ~ X_2 + X_3

  Res.Df    RSS Df Sum of Sq      F  Pr(>F)  
1     48 44.114                              
2     47 39.481  1    4.6339 5.5165 0.02309 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Or we could have simply looked at the t-value provided at the summ table. The p-values are the same for both.

Warning in remove(classical, model.class, X_3): object 'X_3' not found

3 Dummy Variables

Dummy variable dataset, where Group 1, Group 2, and Group 3 are dummy variables.

# A tibble: 3 x 5
    Obs Group1 Group2 Group3 Earnings
  <dbl>  <dbl>  <dbl>  <dbl>    <dbl>
1     1      0      0      1     570.
2     2      0      0      1     896.
3     3      0      0      1    1111 

Regress y on all 3 dummy variables. Important to remove the intercept term. And construct a 0.95 CI of Group3:

model.dum <- lm(Earnings~-1+Group1+Group2+Group3, data=earnings)
summ(model.dum, confint = T, ci.width = 0.95, digits = 2)
MODEL INFO:
Observations: 4266
Dependent Variable: Earnings
Type: OLS linear regression 

MODEL FIT:
F(3,4263) = 3842.49, p = 0.00
R² = 0.73
Adj. R² = 0.73 

Standard errors: OLS
-------------------------------------------------------------
                   Est.       2.5%      97.5%   t val.      p
------------ ---------- ---------- ---------- -------- ------
Group1         22880.48   21964.03   23796.92    48.95   0.00
Group2         25080.17   24335.14   25825.21    66.00   0.00
Group3         27973.63   27180.06   28767.21    69.11   0.00
-------------------------------------------------------------

Regress y on Group3 only:

model.dum3 <- lm(Earnings~-1+Group3, data=earnings)
summ(model.dum3, digits = 2, confint = T, ci.width = 0.95, robust = "HC1")
MODEL INFO:
Observations: 4266
Dependent Variable: Earnings
Type: OLS linear regression 

MODEL FIT:
F(1,4265) = 1849.35, p = 0.00
R² = 0.30
Adj. R² = 0.30 

Standard errors: Robust, type = HC1
-------------------------------------------------------------
                   Est.       2.5%      97.5%   t val.      p
------------ ---------- ---------- ---------- -------- ------
Group3         27973.63   27132.54   28814.73    65.20   0.00
-------------------------------------------------------------

4 Log - Elasticities

5 Cobb-Douglas Function


sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS  10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] AER_1.2-9       survival_3.1-12 sandwich_3.0-0  lmtest_0.9-38  
 [5] zoo_1.8-8       car_3.0-10      carData_3.0-4   gridExtra_2.3  
 [9] GGally_2.0.0    jtools_2.1.1    stargazer_5.2.2 broom_0.5.6    
[13] readxl_1.3.1    forcats_0.5.0   stringr_1.4.0   dplyr_0.8.5    
[17] purrr_0.3.4     readr_1.3.1     tidyr_1.0.3     tibble_3.0.1   
[21] ggplot2_3.3.0   tidyverse_1.3.0 knitr_1.28      workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] nlme_3.1-147       fs_1.4.1           lubridate_1.7.8    RColorBrewer_1.1-2
 [5] httr_1.4.1         rprojroot_1.3-2    tools_4.0.0        backports_1.1.6   
 [9] utf8_1.1.4         R6_2.4.1           DBI_1.1.0          colorspace_1.4-1  
[13] withr_2.2.0        tidyselect_1.1.0   curl_4.3           compiler_4.0.0    
[17] git2r_0.27.1       cli_2.0.2          rvest_0.3.5        xml2_1.3.2        
[21] scales_1.1.1       digest_0.6.25      foreign_0.8-78     rmarkdown_2.6     
[25] rio_0.5.16         pkgconfig_2.0.3    htmltools_0.5.0    highr_0.8         
[29] dbplyr_1.4.3       rlang_0.4.6        rstudioapi_0.11    generics_0.0.2    
[33] jsonlite_1.6.1     zip_2.0.4          magrittr_1.5       Formula_1.2-3     
[37] Matrix_1.2-18      Rcpp_1.0.4.6       munsell_0.5.0      fansi_0.4.1       
[41] abind_1.4-5        lifecycle_0.2.0    stringi_1.4.6      whisker_0.4       
[45] yaml_2.2.1         plyr_1.8.6         grid_4.0.0         promises_1.1.0    
[49] crayon_1.3.4       lattice_0.20-41    haven_2.2.0        splines_4.0.0     
[53] pander_0.6.3       hms_0.5.3          pillar_1.4.4       reprex_0.3.0      
[57] glue_1.4.1         evaluate_0.14      data.table_1.12.8  modelr_0.1.7      
[61] vctrs_0.3.0        httpuv_1.5.2       cellranger_1.1.0   gtable_0.3.0      
[65] reshape_0.8.8      assertthat_0.2.1   xfun_0.19          openxlsx_4.1.5    
[69] later_1.0.0        ellipsis_0.3.0