Загружаем библиотеки и данные:

library(readr)
library(dplyr)
library(tidyr)
library(ggplot2)
library(GGally)
library(sandwich)
library(lmtest)
library(car)
library(broom)
library(xtable)
library(ggpubr)
library(stargazer)
library(modelsummary)
library(haven)
library(readr)
library(margins)
library(ivreg)
library(readxl)
library(writexl)
library("forecast")
library("lmtest")
library("tseries")
library("urca")
library("TSA")
library("rugarch")
library("fGarch")
library(strucchange)
library(plm)
library(dynlm)
data= read_excel("dannye_2.xlsx")

###Пролагарифмируем переменные по потреблению и располагаемому доходу

data$C<- log(data$C)
data$Y<- log(data$Y)

###Почистим пустые строки

data <- data[c(106:158), ]

Проверка временных рядов на стационарность тестом Дики-Фуллера и KPSS-тест ###Исходный показатель потребления

pacf(data$C)

check1 <- ur.df(data$C,type='drift',lags=1,
                selectlags = 'Fixed')
summary(check1)
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression drift 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.027988 -0.004289  0.001914  0.005773  0.016224 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  0.47723    0.37646   1.268    0.211  
## z.lag.1     -0.05191    0.04113  -1.262    0.213  
## z.diff.lag   0.26517    0.13933   1.903    0.063 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.009027 on 48 degrees of freedom
## Multiple R-squared:  0.08757,    Adjusted R-squared:  0.04956 
## F-statistic: 2.304 on 2 and 48 DF,  p-value: 0.1109
## 
## 
## Value of test-statistic is: -1.262 2.1216 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau2 -3.51 -2.89 -2.58
## phi1  6.70  4.71  3.86
kpss_test <- kpss.test(data$C)
## Warning in kpss.test(data$C): p-value smaller than printed p-value
print(kpss_test)
## 
##  KPSS Test for Level Stationarity
## 
## data:  data$C
## KPSS Level = 0.97695, Truncation lag parameter = 3, p-value = 0.01
#не стационарен

###Посчитаем первую разность по потреблению и проверим на стационарность

d1_C <-diff(data$C,differences = 1)
d1_C
##  [1]  0.0048650828  0.0068510204  0.0058995589  0.0162811702  0.0148992546
##  [6]  0.0139635420  0.0013343310  0.0105739687 -0.0008352758 -0.0149490091
## [11]  0.0101103424 -0.0023715840  0.0181110972  0.0165924807  0.0017928419
## [16] -0.0268914204 -0.0110258294 -0.0230467939  0.0119249406 -0.0097678546
## [21]  0.0020087940 -0.0024979208  0.0067392244  0.0004143359 -0.0003131285
## [26]  0.0034131543  0.0085393553  0.0072500046  0.0069264453  0.0057385176
## [31] -0.0141101046 -0.0085285506  0.0034939789  0.0025762699  0.0072454153
## [36]  0.0134413325  0.0021897614 -0.0019138374  0.0046600841  0.0016488772
## [41] -0.0056355865  0.0077266342  0.0085460419  0.0017991078  0.0049523336
## [46]  0.0084896951  0.0067951535  0.0026474821  0.0060772491  0.0059751202
## [51]  0.0063806335  0.0030652317
pacf(d1_C)

check2 <- ur.df(d1_C,type='drift',lags=1,
                selectlags = 'Fixed')
summary(check2)
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression drift 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.031093 -0.004289  0.001654  0.005349  0.016227 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.001835   0.001394   1.316 0.194411    
## z.lag.1     -0.671102   0.178402  -3.762 0.000467 ***
## z.diff.lag  -0.120018   0.144732  -0.829 0.411158    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.009191 on 47 degrees of freedom
## Multiple R-squared:  0.3911, Adjusted R-squared:  0.3651 
## F-statistic: 15.09 on 2 and 47 DF,  p-value: 8.659e-06
## 
## 
## Value of test-statistic is: -3.7617 7.0765 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau2 -3.51 -2.89 -2.58
## phi1  6.70  4.71  3.86
kpss_test2 <- kpss.test(d1_C)
## Warning in kpss.test(d1_C): p-value greater than printed p-value
print(kpss_test2)
## 
##  KPSS Test for Level Stationarity
## 
## data:  d1_C
## KPSS Level = 0.11548, Truncation lag parameter = 3, p-value = 0.1
#стационарен

###Исходный показатель по располагаемому доходу

pacf(data$Y)

check3 <- ur.df(data$Y,type='drift',lags=1,
                selectlags = 'Fixed')
summary(check3)
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression drift 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0254310 -0.0035517 -0.0005497  0.0040373  0.0246515 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept)  0.61817    0.34592   1.787  0.08025 . 
## z.lag.1     -0.06445    0.03618  -1.782  0.08115 . 
## z.diff.lag   0.36465    0.13050   2.794  0.00745 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.008448 on 48 degrees of freedom
## Multiple R-squared:  0.1803, Adjusted R-squared:  0.1461 
## F-statistic: 5.277 on 2 and 48 DF,  p-value: 0.008477
## 
## 
## Value of test-statistic is: -1.7815 2.7265 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau2 -3.51 -2.89 -2.58
## phi1  6.70  4.71  3.86
kpss_test3 <- kpss.test(data$Y)
## Warning in kpss.test(data$Y): p-value smaller than printed p-value
print(kpss_test3)
## 
##  KPSS Test for Level Stationarity
## 
## data:  data$Y
## KPSS Level = 0.95487, Truncation lag parameter = 3, p-value = 0.01
#не стационарен

###Посчитаем первую разность по доходу и проверим на стационарность

d1_Y <-diff(data$Y,differences = 1)

pacf(d1_Y)

check4 <- ur.df(d1_Y,type='drift',lags=1,
                selectlags = 'Fixed')
summary(check4)
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression drift 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.029204 -0.003963 -0.000031  0.005215  0.022116 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)   
## (Intercept)  0.001445   0.001326   1.090  0.28122   
## z.lag.1     -0.553046   0.161978  -3.414  0.00133 **
## z.diff.lag  -0.163645   0.142748  -1.146  0.25744   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.008627 on 47 degrees of freedom
## Multiple R-squared:  0.3514, Adjusted R-squared:  0.3238 
## F-statistic: 12.73 on 2 and 47 DF,  p-value: 3.814e-05
## 
## 
## Value of test-statistic is: -3.4143 5.8644 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau2 -3.51 -2.89 -2.58
## phi1  6.70  4.71  3.86
kpss_test4 <- kpss.test(d1_Y)
## Warning in kpss.test(d1_Y): p-value greater than printed p-value
print(kpss_test4)
## 
##  KPSS Test for Level Stationarity
## 
## data:  d1_Y
## KPSS Level = 0.13696, Truncation lag parameter = 3, p-value = 0.1
#стационарен

###Исходный показатель по процентной ставке

pacf(data$R)

check5 <- ur.df(data$R,type='drift',lags=1,
                selectlags = 'Fixed')
summary(check5)
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression drift 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.99850 -0.10215  0.02235  0.10426  1.24242 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.15106    0.22964  -0.658    0.514
## z.lag.1     -0.02445    0.05665  -0.432    0.668
## z.diff.lag   0.01230    0.15668   0.078    0.938
## 
## Residual standard error: 0.3129 on 48 degrees of freedom
## Multiple R-squared:  0.003871,   Adjusted R-squared:  -0.03763 
## F-statistic: 0.09326 on 2 and 48 DF,  p-value: 0.9111
## 
## 
## Value of test-statistic is: -0.4315 0.8339 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau2 -3.51 -2.89 -2.58
## phi1  6.70  4.71  3.86
kpss_test5 <- kpss.test(data$R)
## Warning in kpss.test(data$R): p-value smaller than printed p-value
print(kpss_test5)
## 
##  KPSS Test for Level Stationarity
## 
## data:  data$R
## KPSS Level = 1.2996, Truncation lag parameter = 3, p-value = 0.01
#не стационарен

###Посчитаем первую разность по процентной ставке и проверим на стационарность

d1_R <-diff(data$R,differences = 1)

pacf(d1_R)

check6 <- ur.df(d1_R,type='drift',lags=2,
                selectlags = 'Fixed')
summary(check6)
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression drift 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.07769 -0.06305  0.03959  0.11701  1.12461 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.07264    0.04561  -1.593   0.1182    
## z.lag.1     -1.46199    0.30546  -4.786 1.87e-05 ***
## z.diff.lag1  0.41182    0.22803   1.806   0.0776 .  
## z.diff.lag2  0.12079    0.15896   0.760   0.4513    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3097 on 45 degrees of freedom
## Multiple R-squared:  0.516,  Adjusted R-squared:  0.4837 
## F-statistic: 15.99 on 3 and 45 DF,  p-value: 3.231e-07
## 
## 
## Value of test-statistic is: -4.7861 11.5527 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau2 -3.51 -2.89 -2.58
## phi1  6.70  4.71  3.86
kpss_test6 <- kpss.test(d1_R)
## Warning in kpss.test(d1_R): p-value greater than printed p-value
print(kpss_test6)
## 
##  KPSS Test for Level Stationarity
## 
## data:  d1_R
## KPSS Level = 0.14459, Truncation lag parameter = 3, p-value = 0.1
#стационарен

###Фильтрация данных

data <- data[c(2:53), ]

data$d1_C <- d1_C
data$d1_Y <- d1_Y
data$d1_R <- d1_R

###Расчитаем 2,3,4,5 разности для переменных дохода, потребления и процентной ставки

data$diff2_Y <-c(NA, NA, diff(data$Y,differences = 2))
data$diff3_Y <-c(NA, NA, NA, diff(data$Y,differences = 3))
data$diff4_Y <-c(NA, NA, NA, NA, diff(data$Y,differences = 4))
data$diff5_Y <-c(NA, NA, NA, NA, NA, diff(data$Y,differences = 5))

data$diff2_C <-c(NA, NA, diff(data$C,differences = 2))
data$diff3_C <-c(NA, NA, NA, diff(data$C,differences = 3))
data$diff4_C <-c(NA, NA, NA, NA, diff(data$C,differences = 4))
data$diff5_C <-c(NA, NA, NA, NA, NA, diff(data$C,differences = 5))

data$diff2_R <-c(NA, NA, diff(data$R,differences = 2))
data$diff3_R <-c(NA, NA, NA, diff(data$R,differences = 3))
data$diff4_R <-c(NA, NA, NA, NA, diff(data$R,differences = 4))
data$diff5_R <-c(NA, NA, NA, NA, NA, diff(data$R,differences = 5))

###Фильтруем данные для регрессий

data <- data[c(6:52), ]

Первая регрессия ###Первая регрессия с использованием первого набора инструментов (разности по доходу, лаги процентной ставки)

#первый шаг МНК
first_stage <- dynlm(d1_Y ~ diff2_Y + diff3_Y + diff4_Y + diff5_Y, data = data)
first_stageR <- dynlm(data$d1_R ~ diff2_R + diff3_R + diff4_R + diff5_R, data = data)
data$Y_hat <- fitted(first_stage)
data$R_hat <- fitted(first_stageR)

#второй шаг МНК
second_stage <- dynlm(data$d1_C ~ Y_hat + R_hat, data = data) 

summary (first_stage)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = d1_Y ~ diff2_Y + diff3_Y + diff4_Y + diff5_Y, 
##     data = data)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.011737 -0.001917  0.000877  0.002675  0.009840 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.0026648  0.0007626   3.495 0.001134 ** 
## diff2_Y      1.9572882  0.2172409   9.010 2.29e-11 ***
## diff3_Y     -2.3725334  0.3752215  -6.323 1.36e-07 ***
## diff4_Y      1.3894593  0.2903232   4.786 2.13e-05 ***
## diff5_Y     -0.2986604  0.0822941  -3.629 0.000765 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.005223 on 42 degrees of freedom
## Multiple R-squared:  0.7052, Adjusted R-squared:  0.6772 
## F-statistic: 25.12 on 4 and 42 DF,  p-value: 1.142e-10
summary (first_stageR)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = data$d1_R ~ diff2_R + diff3_R + diff4_R + diff5_R, 
##     data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.26184 -0.03354  0.00665  0.04175  0.33615 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.04162    0.01465  -2.840  0.00692 ** 
## diff2_R      2.06007    0.14128  14.581  < 2e-16 ***
## diff3_R     -2.06056    0.23031  -8.947 2.79e-11 ***
## diff4_R      1.02858    0.15863   6.484 7.99e-08 ***
## diff5_R     -0.20942    0.04200  -4.986 1.12e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1002 on 42 degrees of freedom
## Multiple R-squared:  0.9098, Adjusted R-squared:  0.9012 
## F-statistic: 105.9 on 4 and 42 DF,  p-value: < 2.2e-16
summary(second_stage)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = data$d1_C ~ Y_hat + R_hat, data = data)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0211196 -0.0021553  0.0002158  0.0042315  0.0139942 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.0005391  0.0010838   0.497    0.621    
## Y_hat       0.7800205  0.1326615   5.880 5.07e-07 ***
## R_hat       0.0042762  0.0033677   1.270    0.211    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.006923 on 44 degrees of freedom
## Multiple R-squared:  0.4611, Adjusted R-squared:  0.4366 
## F-statistic: 18.82 on 2 and 44 DF,  p-value: 1.241e-06
cov <- vcovHC(second_stage, type ="HC0", data= data)
cov1 <- vcovHC(first_stage, type ="HC0", data= data)

#оценки
modelsummary(models = list(second_stage),                      
             vcov = list(cov),                         
             statistic = "std.error",                                     
             stars = TRUE,                                                 
             gof_omit = ".*",                                                
             notes = list("В скобках даны робастные стандартные ошибки"),    
             title = "Результаты оценивания")
Результаты оценивания
Model 1
(Intercept) 0.0005
(0.001)
Y_hat 0.780***
(0.169)
R_hat 0.004*
(0.002)
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001
В скобках даны робастные стандартные ошибки

###Первая регрессия с использованием второго набора инструментов (разности по потреблению, лаги процентной ставки)

#первый шаг МНК
first_stage1 <- dynlm(d1_Y ~ diff2_Y + diff3_Y + diff4_Y + diff5_Y, data = data)
first_stageR <- dynlm(d1_R ~ diff2_R + diff3_R + diff4_R + diff5_R, data = data)
first_stageC <- dynlm(d1_C ~ diff2_C + diff3_C + diff4_C + diff5_C, data = data)

data$Y_hat1 <- fitted(first_stage1)
data$R_hat1 <- fitted(first_stageR)
data$C_hat1 <- fitted(first_stageC)

#второй шаг МНК
second_stage1 <- dynlm(C_hat1 ~ Y_hat1 + R_hat1, data = data) 

summary (first_stage1)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = d1_Y ~ diff2_Y + diff3_Y + diff4_Y + diff5_Y, 
##     data = data)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.011737 -0.001917  0.000877  0.002675  0.009840 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.0026648  0.0007626   3.495 0.001134 ** 
## diff2_Y      1.9572882  0.2172409   9.010 2.29e-11 ***
## diff3_Y     -2.3725334  0.3752215  -6.323 1.36e-07 ***
## diff4_Y      1.3894593  0.2903232   4.786 2.13e-05 ***
## diff5_Y     -0.2986604  0.0822941  -3.629 0.000765 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.005223 on 42 degrees of freedom
## Multiple R-squared:  0.7052, Adjusted R-squared:  0.6772 
## F-statistic: 25.12 on 4 and 42 DF,  p-value: 1.142e-10
summary (first_stageR)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = d1_R ~ diff2_R + diff3_R + diff4_R + diff5_R, 
##     data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.26184 -0.03354  0.00665  0.04175  0.33615 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.04162    0.01465  -2.840  0.00692 ** 
## diff2_R      2.06007    0.14128  14.581  < 2e-16 ***
## diff3_R     -2.06056    0.23031  -8.947 2.79e-11 ***
## diff4_R      1.02858    0.15863   6.484 7.99e-08 ***
## diff5_R     -0.20942    0.04200  -4.986 1.12e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1002 on 42 degrees of freedom
## Multiple R-squared:  0.9098, Adjusted R-squared:  0.9012 
## F-statistic: 105.9 on 4 and 42 DF,  p-value: < 2.2e-16
summary (first_stageC)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = d1_C ~ diff2_C + diff3_C + diff4_C + diff5_C, 
##     data = data)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0134861 -0.0025487  0.0003844  0.0031247  0.0088255 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.0024455  0.0007195   3.399 0.001493 ** 
## diff2_C      1.9342369  0.2073687   9.328 8.60e-12 ***
## diff3_C     -2.1898887  0.3456409  -6.336 1.31e-07 ***
## diff4_C      1.2270339  0.2562682   4.788 2.11e-05 ***
## diff5_C     -0.2595190  0.0708513  -3.663 0.000693 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.004928 on 42 degrees of freedom
## Multiple R-squared:  0.7393, Adjusted R-squared:  0.7145 
## F-statistic: 29.78 on 4 and 42 DF,  p-value: 9.046e-12
summary(second_stage1)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = C_hat1 ~ Y_hat1 + R_hat1, data = data)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0101028 -0.0031976  0.0002331  0.0024417  0.0102247 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.0003474  0.0007063   0.492    0.625    
## Y_hat1      0.8336216  0.0864515   9.643 2.03e-12 ***
## R_hat1      0.0032489  0.0021946   1.480    0.146    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.004512 on 44 degrees of freedom
## Multiple R-squared:  0.6904, Adjusted R-squared:  0.6764 
## F-statistic: 49.07 on 2 and 44 DF,  p-value: 6.263e-12
cov <- vcovHC(second_stage1, type ="HC0", data= data1)
cov1 <- vcovHC(first_stage1, type ="HC0", data= data1)

#оценки
modelsummary(models = list(second_stage1),                      
             vcov = list(cov),                         
             statistic = "std.error",                                     
             stars = TRUE,                                                 
             gof_omit = ".*",                                                
             notes = list("В скобках даны робастные стандартные ошибки"),    
             title = "Результаты оценивания")
Результаты оценивания
Model 1
(Intercept) 0.0003
(0.0007)
Y_hat1 0.834***
(0.081)
R_hat1 0.003*
(0.002)
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001
В скобках даны робастные стандартные ошибки

###Первая регрессия с использованием третьего набора инструментов (разности по потреблению и доходу, лаги процентной ставки, доля первой разности потребления в доходе)

#первый шаг МНК
first_stage2 <- dynlm(d1_Y ~ diff2_C + diff3_C + diff4_C + diff5_C + diff2_Y
                      + diff3_Y + diff4_Y + diff5_Y + CY, data = data)
first_stage3 <- dynlm(d1_R ~ diff2_C + diff3_C + diff4_C + diff5_C + diff2_Y
                      + diff3_Y + diff4_Y + diff5_Y + CY + diff2_R + diff3_R + diff4_R + diff5_R, data = data)
data$Y_hat2 <- fitted(first_stage2)
data$R_hat2 <- fitted(first_stage3)

#второй шаг МНК
second_stage2 <- dynlm(data$d1_C ~ Y_hat2 + R_hat2, data = data) 

summary (first_stage2)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = d1_Y ~ diff2_C + diff3_C + diff4_C + diff5_C + 
##     diff2_Y + diff3_Y + diff4_Y + diff5_Y + CY, data = data)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0119192 -0.0022754  0.0004879  0.0026143  0.0100866 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept)  -0.2946     0.1087  -2.711  0.01012 * 
## diff2_C       0.8079     0.4959   1.629  0.11176   
## diff3_C      -1.0667     0.7423  -1.437  0.15911   
## diff4_C       0.6328     0.4812   1.315  0.19663   
## diff5_C      -0.1352     0.1201  -1.126  0.26756   
## diff2_Y       1.2328     0.4821   2.557  0.01479 * 
## diff3_Y      -1.4763     0.7412  -1.992  0.05380 . 
## diff4_Y       0.8919     0.4945   1.804  0.07944 . 
## diff5_Y      -0.2005     0.1266  -1.584  0.12170   
## CY            0.4476     0.1637   2.735  0.00951 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.005027 on 37 degrees of freedom
## Multiple R-squared:  0.7595, Adjusted R-squared:  0.7009 
## F-statistic: 12.98 on 9 and 37 DF,  p-value: 5.025e-09
summary (first_stage3)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = d1_R ~ diff2_C + diff3_C + diff4_C + diff5_C + 
##     diff2_Y + diff3_Y + diff4_Y + diff5_Y + CY + diff2_R + diff3_R + 
##     diff4_R + diff5_R, data = data)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.244887 -0.039483  0.000491  0.035412  0.310269 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -1.50814    2.29419  -0.657   0.5155    
## diff2_C     -14.89955   10.57848  -1.408   0.1683    
## diff3_C      27.28969   15.81888   1.725   0.0939 .  
## diff4_C     -18.21764   10.46436  -1.741   0.0910 .  
## diff5_C       4.26298    2.66920   1.597   0.1198    
## diff2_Y      13.99146   10.25042   1.365   0.1815    
## diff3_Y     -27.30747   15.69861  -1.739   0.0913 .  
## diff4_Y      19.01776   10.56825   1.800   0.0811 .  
## diff5_Y      -4.60733    2.73618  -1.684   0.1016    
## CY            2.20800    3.45420   0.639   0.5271    
## diff2_R       2.08362    0.15406  13.525 5.17e-15 ***
## diff3_R      -2.10287    0.25445  -8.264 1.52e-09 ***
## diff4_R       1.06299    0.17913   5.934 1.17e-06 ***
## diff5_R      -0.21743    0.04798  -4.531 7.29e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1057 on 33 degrees of freedom
## Multiple R-squared:  0.9211, Adjusted R-squared:   0.89 
## F-statistic: 29.64 on 13 and 33 DF,  p-value: 1.886e-14
summary(second_stage2)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = data$d1_C ~ Y_hat2 + R_hat2, data = data)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0204437 -0.0026423  0.0006557  0.0036578  0.0144499 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.0003738  0.0010022   0.373    0.711    
## Y_hat2      0.8224589  0.1186769   6.930 1.45e-08 ***
## R_hat2      0.0032421  0.0031070   1.043    0.302    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.006417 on 44 degrees of freedom
## Multiple R-squared:  0.537,  Adjusted R-squared:  0.5159 
## F-statistic: 25.51 on 2 and 44 DF,  p-value: 4.397e-08
cov <- vcovHC(second_stage2, type ="HC0", data= data2)
cov1 <- vcovHC(first_stage2, type ="HC0", data= data2)

#оценки
modelsummary(models = list(second_stage2),                      
             vcov = list(cov),                         
             statistic = "std.error",                                     
             stars = TRUE,                                                 
             gof_omit = ".*",                                                
             notes = list("В скобках даны робастные стандартные ошибки"),    
             title = "Результаты оценивания")
Результаты оценивания
Model 1
(Intercept) 0.0004
(0.0009)
Y_hat2 0.822***
(0.130)
R_hat2 0.003+
(0.002)
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001
В скобках даны робастные стандартные ошибки

Вторая регрессия ###Вторая регрессия с использованием первого набора инструментов (разности по доходу, лаги процентной ставки)

#первый шаг МНК
first_stage4 <- dynlm(d1_Y ~ diff2_Y + diff3_Y + diff4_Y + diff5_Y, data = data)
first_stageR <- dynlm(d1_R ~ diff2_R + diff3_R + diff4_R + diff5_R, data = data)

data$Y_hat4 <- fitted(first_stage4)
data$R_hat4 <- fitted(first_stageR)

#второй шаг МНК
second_stage4 <- dynlm(data$d1_C ~ Y_hat4:POS + Y_hat4:NEG + R_hat4, data = data) 

summary (first_stage4)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = d1_Y ~ diff2_Y + diff3_Y + diff4_Y + diff5_Y, 
##     data = data)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.011737 -0.001917  0.000877  0.002675  0.009840 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.0026648  0.0007626   3.495 0.001134 ** 
## diff2_Y      1.9572882  0.2172409   9.010 2.29e-11 ***
## diff3_Y     -2.3725334  0.3752215  -6.323 1.36e-07 ***
## diff4_Y      1.3894593  0.2903232   4.786 2.13e-05 ***
## diff5_Y     -0.2986604  0.0822941  -3.629 0.000765 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.005223 on 42 degrees of freedom
## Multiple R-squared:  0.7052, Adjusted R-squared:  0.6772 
## F-statistic: 25.12 on 4 and 42 DF,  p-value: 1.142e-10
summary (first_stageR)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = d1_R ~ diff2_R + diff3_R + diff4_R + diff5_R, 
##     data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.26184 -0.03354  0.00665  0.04175  0.33615 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.04162    0.01465  -2.840  0.00692 ** 
## diff2_R      2.06007    0.14128  14.581  < 2e-16 ***
## diff3_R     -2.06056    0.23031  -8.947 2.79e-11 ***
## diff4_R      1.02858    0.15863   6.484 7.99e-08 ***
## diff5_R     -0.20942    0.04200  -4.986 1.12e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1002 on 42 degrees of freedom
## Multiple R-squared:  0.9098, Adjusted R-squared:  0.9012 
## F-statistic: 105.9 on 4 and 42 DF,  p-value: < 2.2e-16
summary(second_stage4)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = data$d1_C ~ Y_hat4:POS + Y_hat4:NEG + R_hat4, 
##     data = data)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0178320 -0.0029965  0.0008909  0.0035226  0.0129143 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.002701   0.001357   1.990   0.0530 .  
## R_hat4      0.005006   0.003207   1.561   0.1259    
## Y_hat4:POS  0.397102   0.201201   1.974   0.0549 .  
## Y_hat4:NEG  1.192906   0.210933   5.655 1.16e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.006564 on 43 degrees of freedom
## Multiple R-squared:  0.5265, Adjusted R-squared:  0.4935 
## F-statistic: 15.94 on 3 and 43 DF,  p-value: 4.112e-07
cov <- vcovHC(second_stage4, type ="HC0", data= data)

#оценки
modelsummary(models = list(second_stage4),                      
             vcov = list(cov),                         
             statistic = "std.error",                                     
             stars = TRUE,                                                 
             gof_omit = ".*",                                                
             notes = list("В скобках даны робастные стандартные ошибки"),    
             title = "Результаты оценивания")
Результаты оценивания
Model 1
(Intercept) 0.003+
(0.001)
R_hat4 0.005*
(0.002)
Y_hat4 × POS 0.397
(0.256)
Y_hat4 × NEG 1.193***
(0.238)
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001
В скобках даны робастные стандартные ошибки

###Вторая регрессия с использованием второго набора инструментов (разности по потреблению, лаги процентной ставки)

#первый шаг МНК
first_stage5 <- dynlm(d1_Y ~ diff2_Y + diff3_Y + diff4_Y + diff5_Y, data = data)
first_stageR <- dynlm(d1_R ~ diff2_R + diff3_R + diff4_R + diff5_R, data = data)
first_stageC <- dynlm(d1_C ~ diff2_C + diff3_C + diff4_C + diff5_C, data = data)

data$Y_hat5 <- fitted(first_stage5)
data$R_hat5 <- fitted(first_stageR)
data$C_hat5 <- fitted(first_stageC)

#второй шаг МНК
second_stage5 <- dynlm(C_hat5 ~ Y_hat5:POS + Y_hat5:NEG + R_hat5, data = data) 

summary (first_stage5)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = d1_Y ~ diff2_Y + diff3_Y + diff4_Y + diff5_Y, 
##     data = data)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.011737 -0.001917  0.000877  0.002675  0.009840 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.0026648  0.0007626   3.495 0.001134 ** 
## diff2_Y      1.9572882  0.2172409   9.010 2.29e-11 ***
## diff3_Y     -2.3725334  0.3752215  -6.323 1.36e-07 ***
## diff4_Y      1.3894593  0.2903232   4.786 2.13e-05 ***
## diff5_Y     -0.2986604  0.0822941  -3.629 0.000765 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.005223 on 42 degrees of freedom
## Multiple R-squared:  0.7052, Adjusted R-squared:  0.6772 
## F-statistic: 25.12 on 4 and 42 DF,  p-value: 1.142e-10
summary (first_stageR)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = d1_R ~ diff2_R + diff3_R + diff4_R + diff5_R, 
##     data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.26184 -0.03354  0.00665  0.04175  0.33615 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.04162    0.01465  -2.840  0.00692 ** 
## diff2_R      2.06007    0.14128  14.581  < 2e-16 ***
## diff3_R     -2.06056    0.23031  -8.947 2.79e-11 ***
## diff4_R      1.02858    0.15863   6.484 7.99e-08 ***
## diff5_R     -0.20942    0.04200  -4.986 1.12e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1002 on 42 degrees of freedom
## Multiple R-squared:  0.9098, Adjusted R-squared:  0.9012 
## F-statistic: 105.9 on 4 and 42 DF,  p-value: < 2.2e-16
summary(second_stage5)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = C_hat5 ~ Y_hat5:POS + Y_hat5:NEG + R_hat5, data = data)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0103129 -0.0030684  0.0008908  0.0021867  0.0099211 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.0009551  0.0009328   1.024    0.312    
## R_hat5      0.0034540  0.0022043   1.567    0.124    
## Y_hat5:POS  0.7259619  0.1382975   5.249 4.46e-06 ***
## Y_hat5:NEG  0.9497067  0.1449871   6.550 5.78e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.004512 on 43 degrees of freedom
## Multiple R-squared:  0.6974, Adjusted R-squared:  0.6763 
## F-statistic: 33.04 on 3 and 43 DF,  p-value: 3.089e-11
cov <- vcovHC(second_stage5, type ="HC0", data= data)

modelsummary(models = list(second_stage5),                      
             vcov = list(cov),                         
             statistic = "std.error",                                    
             stars = TRUE,                                                
             gof_omit = ".*",                                             
             notes = list("В скобках даны робастные стандартные ошибки"), 
             title = "Результаты оценивания")
Результаты оценивания
Model 1
(Intercept) 0.001
(0.0008)
R_hat5 0.003*
(0.001)
Y_hat5 × POS 0.726***
(0.140)
Y_hat5 × NEG 0.950***
(0.081)
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001
В скобках даны робастные стандартные ошибки

###Вторая регрессия с использованием третьего набора инструментов (разности по потреблению и доходу, лаги процентной ставки, доля первой разности потребления в доходе)

#первый шаг МНК
first_stage6 <- dynlm(d1_Y ~ diff2_Y + diff3_Y + diff4_Y + diff5_Y + CY, data = data)
first_stageR <- dynlm(d1_R ~ diff2_Y + diff3_Y + diff4_Y + diff5_Y + CY + diff2_R + diff3_R + diff4_R + diff5_R, data = data)

data$Y_hat6 <- fitted(first_stage6)
data$R_hat6 <- fitted(first_stageR)

#второй шаг МНК
second_stage6 <- dynlm(data$d1_C ~ Y_hat6:POS + Y_hat6:NEG + R_hat6, data = data) 

summary (first_stage6)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = d1_Y ~ diff2_Y + diff3_Y + diff4_Y + diff5_Y + 
##     CY, data = data)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0116884 -0.0014946  0.0004741  0.0027272  0.0129005 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.19986    0.08929  -2.238 0.030684 *  
## diff2_Y      1.92779    0.20766   9.283 1.24e-11 ***
## diff3_Y     -2.37964    0.35798  -6.647 5.20e-08 ***
## diff4_Y      1.39624    0.27699   5.041 9.84e-06 ***
## diff5_Y     -0.29824    0.07851  -3.799 0.000473 ***
## CY           0.30492    0.13442   2.268 0.028640 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.004983 on 41 degrees of freedom
## Multiple R-squared:  0.7381, Adjusted R-squared:  0.7062 
## F-statistic: 23.11 on 5 and 41 DF,  p-value: 5.843e-11
summary (first_stageR)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = d1_R ~ diff2_Y + diff3_Y + diff4_Y + diff5_Y + 
##     CY + diff2_R + diff3_R + diff4_R + diff5_R, data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.26939 -0.02487  0.01051  0.03882  0.32222 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.91538    1.90226  -1.007    0.321    
## diff2_Y      1.08717    4.41604   0.246    0.807    
## diff3_Y     -3.92539    7.58761  -0.517    0.608    
## diff4_Y      3.63962    5.84768   0.622    0.537    
## diff5_Y     -1.07611    1.65445  -0.650    0.519    
## CY           2.82133    2.86392   0.985    0.331    
## diff2_R      2.05456    0.15034  13.666 4.93e-16 ***
## diff3_R     -2.04325    0.24539  -8.327 5.25e-10 ***
## diff4_R      1.01909    0.16873   6.040 5.54e-07 ***
## diff5_R     -0.20795    0.04463  -4.660 4.02e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1048 on 37 degrees of freedom
## Multiple R-squared:  0.9131, Adjusted R-squared:  0.892 
## F-statistic:  43.2 on 9 and 37 DF,  p-value: < 2.2e-16
summary(second_stage6)
## 
## Time series regression with "numeric" data:
## Start = 1, End = 47
## 
## Call:
## dynlm(formula = data$d1_C ~ Y_hat6:POS + Y_hat6:NEG + R_hat6, 
##     data = data)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0181069 -0.0029775  0.0006677  0.0038979  0.0145097 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.002394   0.001463   1.636   0.1091    
## R_hat6      0.004804   0.003389   1.417   0.1636    
## Y_hat6:POS  0.416907   0.220650   1.889   0.0656 .  
## Y_hat6:NEG  1.020457   0.207681   4.914 1.34e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.006957 on 43 degrees of freedom
## Multiple R-squared:  0.4682, Adjusted R-squared:  0.4311 
## F-statistic: 12.62 on 3 and 43 DF,  p-value: 4.732e-06
cov <- vcovHC(second_stage6, type ="HC0", data= data)

#оценки
modelsummary(models = list(second_stage6),                      
             vcov = list(cov),                         
             statistic = "std.error",                                     
             stars = TRUE,                                                 
             gof_omit = ".*",                                                
             notes = list("В скобках даны робастные стандартные ошибки"),    
             title = "Результаты оценивания")
Результаты оценивания
Model 1
(Intercept) 0.002
(0.002)
R_hat6 0.005*
(0.002)
Y_hat6 × POS 0.417
(0.284)
Y_hat6 × NEG 1.020***
(0.212)
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001
В скобках даны робастные стандартные ошибки

```