#Downloading needed libraries
# library(tidyverse)
# library(broom)
# library(haven)
# library(AER)
# library(sandwich)
# library(lmtest)
# library(car)
# library(stargazer)
library(dplyr) 
# library(ggplot2)
# library(GGally)
library(psych)
# library(corrplot)
library(readxl)
library(writexl)
library(kableExtra)
# 
# #TS data 
# library(quantmod)
# library(tseries)
# library(forecast)
# 
# #TS graphs 
# library(quantmod)
# library(tseries)
# library(forecast)
# 
# library(TSstudio)
# library(reshape2)
# library(plotly)
# 
# #Histograms 
# library(hrbrthemes)
# library(viridis)
# library(forcats)
# 
# #Spatial analysis
# # geo
# library(sp)
# library(spdep)
# library(rgdal)
# library(maptools)
# library(rgeos)
# library(sf)
# library(spatialreg)
# 
# # mass retype()
# library(hablar)
# 
# # multicollinearity test omcdiag imcdiag
# library(mctest)
# 
# library(GGally)
# 
# # Panel
# 
# library(plm)
# library(lmtest)
# library(xtable)
library(tidyverse)
## Warning: пакет 'tidyverse' был собран под R версии 4.1.3
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.6     v stringr 1.4.0
## v tidyr   1.2.0     v forcats 0.5.1
## v readr   2.1.2
## Warning: пакет 'tidyr' был собран под R версии 4.1.3
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x ggplot2::%+%()           masks psych::%+%()
## x ggplot2::alpha()         masks psych::alpha()
## x dplyr::filter()          masks stats::filter()
## x kableExtra::group_rows() masks dplyr::group_rows()
## x dplyr::lag()             masks stats::lag()
library(plm)
## 
## Присоединяю пакет: 'plm'
## Следующие объекты скрыты от 'package:dplyr':
## 
##     between, lag, lead
library(sandwich)
library(lmtest)
## Загрузка требуемого пакета: zoo
## 
## Присоединяю пакет: 'zoo'
## Следующие объекты скрыты от 'package:base':
## 
##     as.Date, as.Date.numeric
library(xtable)
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
wide_data <- read_xlsx('C:/Users/Kolya/Documents/New_studies/Term_paper/Data/Raw data/Common_dataset_new.xlsx')

### LONG vs.WIDE format
long_data <- wide_data %>% pivot_longer(cols = !region, 
                                            names_to = c(".value", "year"), 
                                            names_pattern = "([A-Za-z]+)_(\\d+)")
# ### second variant - smth is wrong
# data<-reshape(wide_data, direction = 'long', idvar = 'region', varying = 2:ncol(wide_data), sep = '_')
# 
# ### third variant
# datalong <- melt(wide_data, id.vars = 'region') #region var
# datalong <- cbind(datalong, colsplit(datalong$variable, '_', c('var', 'year')))#cells for variables
# datalong <- dcast(datalong, region + year ~ var, value.var = 'value') #assignment of panel structure
# Descriptive statistics 
number <- function(x, na.rm = TRUE){return(sum(!is.na(x)))}

#not good for many observations
desc <- long_data %>% 
  select(-region) %>%
  # select(year, pop, crimes) %>% 
  group_by(year) %>%
  summarise(across(where(is.numeric), 
                   list(n = number, mean = mean, median = median, sd = sd, min = min, max = max), 
                   na.rm = TRUE)) %>% 
  pivot_longer(!year, names_to = "name", values_to = "value") %>% 
  separate(name, c("variable", "statistic"), sep = "_") %>%
  pivot_wider(names_from = statistic, values_from = value) %>%
  arrange(variable, year) %>% 
  select(variable, year, n, mean, median, sd, min, max)

desc
desc %>% xtable()
#good for many observations - doesn't work
# desc_2 <- long_data %>% #beautiful table
#   # select(totexp, posexp, suppins, phylim, actlim, totchr, age, female, income) %>%
#   summarise(across(everything(), 
#                    list(n = number, mean = mean, median = median, sd = sd, min = min, max = max), 
#                    na.rm = TRUE)) %>% 
#   pivot_longer(everything(), names_to = "name", values_to = "value") %>% 
#   separate(name, c("variable", "statistic"), sep = "_") %>%
#   pivot_wider(names_from = statistic, values_from = value) %>%
#   arrange(variable) %>% 
#   select(variable, n, mean, median, sd, min, max)
long_data %>% summary()
##     region              year                educ             GRP          
##  Length:948         Length:948         Min.   :  13.0   Min.   :    9034  
##  Class :character   Class :character   1st Qu.: 280.0   1st Qu.:  132914  
##  Mode  :character   Mode  :character   Median : 366.0   Median :  275439  
##                                        Mean   : 375.9   Mean   :  611286  
##                                        3rd Qu.: 449.5   3rd Qu.:  579415  
##                                        Max.   :1254.0   Max.   :16538190  
##                                        NA's   :5                          
##      LabPr           Unemp             Wage          EmpPerWF        
##  Min.   : 84.0   Min.   : 0.800   Min.   : 81.6   Min.   :0.0002465  
##  1st Qu.:100.9   1st Qu.: 5.100   1st Qu.: 98.7   1st Qu.:0.0087923  
##  Median :103.2   Median : 6.500   Median :103.0   Median :0.0129767  
##  Mean   :103.2   Mean   : 7.438   Mean   :104.1   Mean   :0.0146494  
##  3rd Qu.:105.7   3rd Qu.: 8.400   3rd Qu.:108.9   3rd Qu.:0.0179141  
##  Max.   :123.9   Max.   :57.800   Max.   :132.4   Max.   :0.0997954  
##                                                                      
##       Inv               V                Rv               Uv        
##  Min.   :  6525   Min.   :0.8476   Min.   :0.0000   Min.   :0.8476  
##  1st Qu.: 36619   1st Qu.:2.6594   1st Qu.:0.3174   1st Qu.:2.2831  
##  Median : 56129   Median :3.3077   Median :0.5030   Median :2.7238  
##  Mean   : 73588   Mean   :3.3179   Mean   :0.5827   Mean   :2.7352  
##  3rd Qu.: 82885   3rd Qu.:3.8525   3rd Qu.:0.7372   3rd Qu.:3.1534  
##  Max.   :623234   Max.   :7.2797   Max.   :4.7498   Max.   :5.0489  
## 
long_data %>% summary()
##     region              year                educ             GRP          
##  Length:948         Length:948         Min.   :  13.0   Min.   :    9034  
##  Class :character   Class :character   1st Qu.: 280.0   1st Qu.:  132914  
##  Mode  :character   Mode  :character   Median : 366.0   Median :  275439  
##                                        Mean   : 375.9   Mean   :  611286  
##                                        3rd Qu.: 449.5   3rd Qu.:  579415  
##                                        Max.   :1254.0   Max.   :16538190  
##                                        NA's   :5                          
##      LabPr           Unemp             Wage          EmpPerWF        
##  Min.   : 84.0   Min.   : 0.800   Min.   : 81.6   Min.   :0.0002465  
##  1st Qu.:100.9   1st Qu.: 5.100   1st Qu.: 98.7   1st Qu.:0.0087923  
##  Median :103.2   Median : 6.500   Median :103.0   Median :0.0129767  
##  Mean   :103.2   Mean   : 7.438   Mean   :104.1   Mean   :0.0146494  
##  3rd Qu.:105.7   3rd Qu.: 8.400   3rd Qu.:108.9   3rd Qu.:0.0179141  
##  Max.   :123.9   Max.   :57.800   Max.   :132.4   Max.   :0.0997954  
##                                                                      
##       Inv               V                Rv               Uv        
##  Min.   :  6525   Min.   :0.8476   Min.   :0.0000   Min.   :0.8476  
##  1st Qu.: 36619   1st Qu.:2.6594   1st Qu.:0.3174   1st Qu.:2.2831  
##  Median : 56129   Median :3.3077   Median :0.5030   Median :2.7238  
##  Mean   : 73588   Mean   :3.3179   Mean   :0.5827   Mean   :2.7352  
##  3rd Qu.: 82885   3rd Qu.:3.8525   3rd Qu.:0.7372   3rd Qu.:3.1534  
##  Max.   :623234   Max.   :7.2797   Max.   :4.7498   Max.   :5.0489  
## 
tex_desc_stat <- long_data[, c(3:length(names(long_data)))] %>% describe() #good, but not LaTeX
tex_desc_stat <- tex_desc_stat[, c(3:5, 8:9 )]

tex_desc_stat %>% xtable()
# kbl(tex_desc_stat, format = "text")

#Specifications

###Pannel models

#Specifications V
grp_V <- log(GRP) ~ V + log(Inv) + educ + Wage
labpr_V <- LabPr ~ V + log(Inv) + educ + Wage
emp_V <- EmpPerWF ~ V + log(Inv) + educ + Wage
unemp_V <- Unemp ~ V + log(Inv) + educ + Wage

#Specifications RV, UV
grp_RV_UV <- log(GRP) ~ Rv + Uv + log(Inv) + educ + Wage
labpr_RV_UV <- LabPr ~ Rv + Uv + log(Inv) + educ + Wage
emp_RV_UV <- EmpPerWF ~ Rv + Uv + log(Inv) + educ + Wage
unemp_RV_UV <- Unemp ~ Rv + Uv + log(Inv) + educ + Wage


###Extra models with time-effects
#Specifications V, t

grp_V_t<- log(GRP) ~ V + log(Inv) + educ + Wage + factor(year)
labpr_V_t <- LabPr ~ V + log(Inv) + educ + Wage + factor(year)
emp_V_t <- EmpPerWF ~ V + log(Inv) + educ + Wage  + factor(year)
unemp_V_t <- Unemp ~ V + log(Inv) + educ + Wage  + factor(year)

#Specifications RV, UV, t
grp_RV_UV_t<- log(GRP) ~ Rv + Uv + log(Inv) + educ + Wage + factor(year)
labpr_RV_UV_t <- LabPr ~ Rv + Uv + log(Inv) + educ + Wage + factor(year)
emp_RV_UV_t <- EmpPerWF ~ Rv + Uv + log(Inv) + educ + Wage  + factor(year)
unemp_RV_UV_t <- Unemp ~ Rv + Uv + log(Inv) + educ + Wage  + factor(year)

#Simple models for value-added growth V, without time-effects

# grp_V_time <- log(grp_V) ~ V + log(Inv) + educ + Wage + factor(year)
ols_plm_grp_V <- plm(grp_V, 
               data = long_data, 
               index = c("region", "year"),
               model = "pooling")
cov_ols_plm_grp_V <- vcovHC(ols_plm_grp_V, type = "HC0")
se_ols_plm_grp_V <- sqrt(diag(cov_ols_plm_grp_V))
coeftest(ols_plm_grp_V, df = Inf, vcov = cov_ols_plm_grp_V)
## 
## z test of coefficients:
## 
##                Estimate  Std. Error z value  Pr(>|z|)    
## (Intercept)  3.79025361  1.91630511  1.9779 0.0479404 *  
## V            0.44536099  0.08196861  5.4333 5.532e-08 ***
## log(Inv)     0.84284763  0.14381909  5.8605 4.616e-09 ***
## educ         0.00138918  0.00093661  1.4832 0.1380202    
## Wage        -0.02371371  0.00711836 -3.3313 0.0008643 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
fe_ind_grp_V <- plm(grp_V, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_grp_V <- vcovHC(fe_ind_grp_V, type = "HC0")
se_fe_ind_grp_V <- sqrt(diag(cov_fe_ind_grp_V))
coeftest(fe_ind_grp_V, df = Inf, vcov = cov_fe_ind_grp_V)
## 
## z test of coefficients:
## 
##             Estimate  Std. Error z value  Pr(>|z|)    
## V        -0.02826253  0.01762951 -1.6031    0.1089    
## log(Inv)  0.51869449  0.03001834 17.2793 < 2.2e-16 ***
## educ     -0.00192108  0.00028119 -6.8320 8.372e-12 ***
## Wage     -0.00955683  0.00109580 -8.7213 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_grp_V) #
re_grp_V <- plm(grp_V, 
              data = long_data, 
              index = c("region", "year"),
              model = "random")
cov_re_grp_V <- vcovHC(re_grp_V, type = "HC0")
se_re_grp_V <- sqrt(diag(cov_re_grp_V))
coeftest(re_grp_V, df = Inf, vcov = cov_re_grp_V)
## 
## z test of coefficients:
## 
##                Estimate  Std. Error z value  Pr(>|z|)    
## (Intercept)  8.54160693  0.39062712 21.8664 < 2.2e-16 ***
## V           -0.01925275  0.01725434 -1.1158    0.2645    
## log(Inv)     0.52759795  0.03139337 16.8060 < 2.2e-16 ***
## educ        -0.00185355  0.00028993 -6.3931 1.625e-10 ***
## Wage        -0.00985371  0.00110186 -8.9428 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#Tests for model for value-added growth V, without time-effects

#Ftest - between fixed effects and pooled OLS
#H0 - pooled OLS are better than fixed effects (because all individual effects are the same)
#H1 - fixed effects are better than pooled OLS ones
pFtest(fe_ind_grp_V, ols_plm_grp_V)
## 
##  F test for individual effects
## 
## data:  grp_V
## F = 415.29, df1 = 78, df2 = 860, p-value < 2.2e-16
## alternative hypothesis: significant effects
#fixed effects are better, as expected
#plmtest - between random effects and pooled OLS
#H0 - pooled OLS are better than random effects (because all random effects are the same - on penal effect)
#H1 - random effects are better than pooled OLS ones
plmtest(ols_plm_grp_V, type = c('bp'))
## 
##  Lagrange Multiplier Test - (Breusch-Pagan) for unbalanced panels
## 
## data:  grp_V
## chisq = 3500.2, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
#random effects are better, as expected
#phtest - between fixed effects and random effects
#H0 - random effects are better than fixed effects (random coef. are more efficient)
#H1 - fixed effects are better than random effects (fixed coef. are more efficient)
phtest(fe_ind_grp_V, re_grp_V)
## 
##  Hausman Test
## 
## data:  grp_V
## chisq = 19.137, df = 4, p-value = 0.0007387
## alternative hypothesis: one model is inconsistent
#random effects are then fixed ones - unexpected

#fixed effects are better than random effects
stargazer(ols_plm_grp_V, fe_ind_grp_V, re_grp_V, se = list(se_ols_plm_grp_V, se_fe_ind_grp_V, se_re_grp_V), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## ==========================================
##                   Dependent variable:     
##              -----------------------------
##                        log(GRP)           
##                 (1)       (2)       (3)   
## ------------------------------------------
## V            0.445***   -0.028    -0.019  
##               (0.082)   (0.018)   (0.017) 
##                                           
## log(Inv)     0.843***  0.519***  0.528*** 
##               (0.144)   (0.030)   (0.031) 
##                                           
## educ           0.001   -0.002*** -0.002***
##               (0.001)  (0.0003)  (0.0003) 
##                                           
## Wage         -0.024*** -0.010*** -0.010***
##               (0.007)   (0.001)   (0.001) 
##                                           
## ------------------------------------------
## Observations    943       943       943   
## ==========================================
## Note:          *p<0.1; **p<0.05; ***p<0.01

#Extra models with time-effects, GRP, V

#extra
fe_ind_grp_V_t <- plm(grp_V_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "twoways",
              model = "within")
cov_fe_ind_grp_V_t <- vcovHC(fe_ind_grp_V_t, type = "HC0")
se_fe_ind_grp_V_t <- sqrt(diag(cov_fe_ind_grp_V_t))
coeftest(fe_ind_grp_V_t, df = Inf, vcov = cov_fe_ind_grp_V_t)
## 
## z test of coefficients:
## 
##             Estimate  Std. Error z value  Pr(>|z|)    
## V        -1.5075e-02  1.2860e-02 -1.1722    0.2411    
## log(Inv)  1.3465e-01  2.7433e-02  4.9083 9.189e-07 ***
## educ      3.1351e-05  1.7391e-04  0.1803    0.8569    
## Wage      8.8206e-05  6.4925e-04  0.1359    0.8919    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_grp_V) #
#extra

fe_ind_grp_V_t_i <- plm(grp_V_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_grp_V_t_i <- vcovHC(fe_ind_grp_V_t_i, type = "HC0")
se_fe_ind_grp_V_t_i <- sqrt(diag(cov_fe_ind_grp_V_t_i))
coeftest(fe_ind_grp_V_t_i, df = Inf, vcov = cov_fe_ind_grp_V_t_i)
## 
## z test of coefficients:
## 
##                     Estimate  Std. Error z value  Pr(>|z|)    
## V                -1.5075e-02  1.2860e-02 -1.1722    0.2411    
## log(Inv)          1.3465e-01  2.7433e-02  4.9083 9.189e-07 ***
## educ              3.1351e-05  1.7391e-04  0.1803    0.8569    
## Wage              8.8206e-05  6.4925e-04  0.1359    0.8919    
## factor(year)2007  1.7206e-01  1.5365e-02 11.1978 < 2.2e-16 ***
## factor(year)2008  3.2938e-01  2.1779e-02 15.1236 < 2.2e-16 ***
## factor(year)2009  3.3322e-01  2.3864e-02 13.9634 < 2.2e-16 ***
## factor(year)2010  4.7301e-01  2.8011e-02 16.8864 < 2.2e-16 ***
## factor(year)2011  6.3252e-01  3.4951e-02 18.0973 < 2.2e-16 ***
## factor(year)2012  7.1949e-01  3.8282e-02 18.7946 < 2.2e-16 ***
## factor(year)2013  7.9431e-01  4.1341e-02 19.2133 < 2.2e-16 ***
## factor(year)2014  8.8176e-01  4.4068e-02 20.0087 < 2.2e-16 ***
## factor(year)2015  9.8542e-01  4.5988e-02 21.4278 < 2.2e-16 ***
## factor(year)2016  1.1065e+00  5.0512e-02 21.9046 < 2.2e-16 ***
## factor(year)2017  1.1599e+00  5.2468e-02 22.1071 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_grp_V) #
stargazer(fe_ind_grp_V_t, fe_ind_grp_V_t_i, se = list(se_fe_ind_grp_V_t, se_fe_ind_grp_V_t_i), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## =============================================
##                      Dependent variable:     
##                  ----------------------------
##                            log(GRP)          
##                       (1)            (2)     
## ---------------------------------------------
## V                    -0.015        -0.015    
##                     (0.013)        (0.013)   
##                                              
## log(Inv)            0.135***      0.135***   
##                     (0.027)        (0.027)   
##                                              
## educ                0.00003        0.00003   
##                     (0.0002)      (0.0002)   
##                                              
## Wage                 0.0001        0.0001    
##                     (0.001)        (0.001)   
##                                              
## factor(year)2007                  0.172***   
##                                    (0.015)   
##                                              
## factor(year)2008                  0.329***   
##                                    (0.022)   
##                                              
## factor(year)2009                  0.333***   
##                                    (0.024)   
##                                              
## factor(year)2010                  0.473***   
##                                    (0.028)   
##                                              
## factor(year)2011                  0.633***   
##                                    (0.035)   
##                                              
## factor(year)2012                  0.719***   
##                                    (0.038)   
##                                              
## factor(year)2013                  0.794***   
##                                    (0.041)   
##                                              
## factor(year)2014                  0.882***   
##                                    (0.044)   
##                                              
## factor(year)2015                  0.985***   
##                                    (0.046)   
##                                              
## factor(year)2016                  1.106***   
##                                    (0.051)   
##                                              
## factor(year)2017                  1.160***   
##                                    (0.052)   
##                                              
## ---------------------------------------------
## Observations          943            943     
## =============================================
## Note:             *p<0.1; **p<0.05; ***p<0.01
#no changes
#pFtest(fixed.time, fixed)
#H0 - time effects are unnecessary  
pFtest(fe_ind_grp_V_t_i, fe_ind_grp_V)
## 
##  F test for individual effects
## 
## data:  grp_V_t
## F = 174.24, df1 = 11, df2 = 849, p-value < 2.2e-16
## alternative hypothesis: significant effects
# time effects are needed

#plmtest(fixed, c("time"), type=("bp"))
#H0 - time effects are unnecessary 
plmtest(fe_ind_grp_V, c("time"), type=("bp"))
## 
##  Lagrange Multiplier Test - time effects (Breusch-Pagan) for unbalanced
##  panels
## 
## data:  grp_V
## chisq = 92.081, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
# time effects are needed

#so, fe_ind_grp_V_t is the best model (twoways or individual- we are free to choose)

#Simple models for value-added growth (RV, UV), without time-effects

ols_plm_grp_RV_UV <- plm(grp_RV_UV, 
               data = long_data, 
               index = c("region", "year"),
               model = "pooling")
cov_ols_plm_grp_RV_UV <- vcovHC(ols_plm_grp_RV_UV, type = "HC0")
se_ols_plm_grp_RV_UV <- sqrt(diag(cov_ols_plm_grp_RV_UV))
coeftest(ols_plm_grp_RV_UV, df = Inf, vcov = cov_ols_plm_grp_RV_UV)
## 
## z test of coefficients:
## 
##                Estimate  Std. Error z value  Pr(>|z|)    
## (Intercept)  3.49326554  1.92311226  1.8165 0.0692991 .  
## Rv           0.11828061  0.13068814  0.9051 0.3654336    
## Uv           0.65160115  0.14227131  4.5800 4.650e-06 ***
## log(Inv)     0.86977182  0.14140460  6.1509 7.702e-10 ***
## educ         0.00109896  0.00099407  1.1055 0.2689331    
## Wage        -0.02622851  0.00694625 -3.7759 0.0001594 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
fe_ind_grp_RV_UV <- plm(grp_RV_UV, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_grp_RV_UV <- vcovHC(fe_ind_grp_RV_UV, type = "HC0")
se_fe_ind_grp_RV_UV <- sqrt(diag(cov_fe_ind_grp_RV_UV))
coeftest(fe_ind_grp_RV_UV, df = Inf, vcov = cov_fe_ind_grp_RV_UV)
## 
## z test of coefficients:
## 
##             Estimate  Std. Error z value  Pr(>|z|)    
## Rv        0.08323036  0.03724341  2.2348  0.025433 *  
## Uv       -0.09431496  0.03512445 -2.6852  0.007249 ** 
## log(Inv)  0.50744927  0.02934671 17.2915 < 2.2e-16 ***
## educ     -0.00183886  0.00028028 -6.5607 5.355e-11 ***
## Wage     -0.00901557  0.00105597 -8.5377 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_grp_RV_UV) #
re_grp_RV_UV <- plm(grp_RV_UV, 
              data = long_data, 
              index = c("region", "year"),
              model = "random")
cov_re_grp_RV_UV <- vcovHC(re_grp_RV_UV, type = "HC0")
se_re_grp_RV_UV <- sqrt(diag(cov_re_grp_RV_UV))
coeftest(re_grp_RV_UV, df = Inf, vcov = cov_re_grp_RV_UV)
## 
## z test of coefficients:
## 
##                Estimate  Std. Error z value  Pr(>|z|)    
## (Intercept)  8.68711908  0.38741763 22.4231 < 2.2e-16 ***
## Rv           0.08724609  0.03551553  2.4566   0.01403 *  
## Uv          -0.08252838  0.03466634 -2.3806   0.01728 *  
## log(Inv)     0.51678021  0.03052683 16.9287 < 2.2e-16 ***
## educ        -0.00177547  0.00028932 -6.1367 8.425e-10 ***
## Wage        -0.00933205  0.00105954 -8.8076 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#Tests for model for value-added growth (RV, UV), without time-effects

#Ftest - between fixed effects and pooled OLS
#H0 - pooled OLS are better than fixed effects (because all individual effects are the same)
#H1 - fixed effects are better than pooled OLS ones
pFtest(fe_ind_grp_RV_UV, ols_plm_grp_RV_UV)
## 
##  F test for individual effects
## 
## data:  grp_RV_UV
## F = 416.3, df1 = 78, df2 = 859, p-value < 2.2e-16
## alternative hypothesis: significant effects
#fixed effects are better, as expected
#plmtest - between random effects and pooled OLS
#H0 - pooled OLS are better than random effects (because all random effects are the same - on penal effect)
#H1 - random effects are better than pooled OLS ones
plmtest(ols_plm_grp_RV_UV, type = c('bp'))
## 
##  Lagrange Multiplier Test - (Breusch-Pagan) for unbalanced panels
## 
## data:  grp_RV_UV
## chisq = 3368.4, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
#random effects are better, as expected
#phtest - between fixed effects and random effects
#H0 - random effects are better than fixed effects (random coef. are more efficient)
#H1 - fixed effects are better than random effects (fixed coef. are more efficient)
phtest(fe_ind_grp_RV_UV, re_grp_RV_UV)
## 
##  Hausman Test
## 
## data:  grp_RV_UV
## chisq = 18.563, df = 5, p-value = 0.002318
## alternative hypothesis: one model is inconsistent
#random effects are then fixed ones - unexpected

#fixed effects are better than random effects
stargazer(ols_plm_grp_RV_UV, fe_ind_grp_RV_UV, re_grp_RV_UV, se = list(se_ols_plm_grp_RV_UV, se_fe_ind_grp_RV_UV, se_re_grp_RV_UV), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## ==========================================
##                   Dependent variable:     
##              -----------------------------
##                        log(GRP)           
##                 (1)       (2)       (3)   
## ------------------------------------------
## Rv             0.118    0.083**   0.087** 
##               (0.131)   (0.037)   (0.036) 
##                                           
## Uv           0.652***  -0.094*** -0.083** 
##               (0.142)   (0.035)   (0.035) 
##                                           
## log(Inv)     0.870***  0.507***  0.517*** 
##               (0.141)   (0.029)   (0.031) 
##                                           
## educ           0.001   -0.002*** -0.002***
##               (0.001)  (0.0003)  (0.0003) 
##                                           
## Wage         -0.026*** -0.009*** -0.009***
##               (0.007)   (0.001)   (0.001) 
##                                           
## ------------------------------------------
## Observations    943       943       943   
## ==========================================
## Note:          *p<0.1; **p<0.05; ***p<0.01

#Extra models with time-effects, GRP, RV, UV

#extra
fe_ind_grp_RV_UV_t <- plm(grp_RV_UV_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "twoways",
              model = "within")
cov_fe_ind_grp_RV_UV_t <- vcovHC(fe_ind_grp_RV_UV_t, type = "HC0")
se_fe_ind_grp_RV_UV_t <- sqrt(diag(cov_fe_ind_grp_RV_UV_t))
coeftest(fe_ind_grp_RV_UV_t, df = Inf, vcov = cov_fe_ind_grp_RV_UV_t)
## 
## z test of coefficients:
## 
##             Estimate  Std. Error z value  Pr(>|z|)    
## Rv       -1.5925e-02  2.8649e-02 -0.5559    0.5783    
## Uv       -1.4549e-02  1.9979e-02 -0.7282    0.4665    
## log(Inv)  1.3465e-01  2.7423e-02  4.9100 9.109e-07 ***
## educ      3.1561e-05  1.7361e-04  0.1818    0.8557    
## Wage      8.9917e-05  6.6014e-04  0.1362    0.8917    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_grp_RV_UV) #
#extra

fe_ind_grp_RV_UV_t_i <- plm(grp_RV_UV_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_grp_RV_UV_t_i <- vcovHC(fe_ind_grp_RV_UV_t_i, type = "HC0")
se_fe_ind_grp_RV_UV_t_i <- sqrt(diag(cov_fe_ind_grp_RV_UV_t_i))
coeftest(fe_ind_grp_RV_UV_t_i, df = Inf, vcov = cov_fe_ind_grp_RV_UV_t_i)
## 
## z test of coefficients:
## 
##                     Estimate  Std. Error z value  Pr(>|z|)    
## Rv               -1.5925e-02  2.8649e-02 -0.5559    0.5783    
## Uv               -1.4549e-02  1.9979e-02 -0.7282    0.4665    
## log(Inv)          1.3465e-01  2.7423e-02  4.9100 9.109e-07 ***
## educ              3.1561e-05  1.7361e-04  0.1818    0.8557    
## Wage              8.9917e-05  6.6014e-04  0.1362    0.8917    
## factor(year)2007  1.7202e-01  1.5464e-02 11.1239 < 2.2e-16 ***
## factor(year)2008  3.2934e-01  2.1829e-02 15.0875 < 2.2e-16 ***
## factor(year)2009  3.3334e-01  2.3929e-02 13.9304 < 2.2e-16 ***
## factor(year)2010  4.7305e-01  2.7943e-02 16.9288 < 2.2e-16 ***
## factor(year)2011  6.3275e-01  3.5155e-02 17.9988 < 2.2e-16 ***
## factor(year)2012  7.1970e-01  3.7929e-02 18.9750 < 2.2e-16 ***
## factor(year)2013  7.9450e-01  4.0740e-02 19.5018 < 2.2e-16 ***
## factor(year)2014  8.8201e-01  4.3465e-02 20.2923 < 2.2e-16 ***
## factor(year)2015  9.8573e-01  4.5603e-02 21.6155 < 2.2e-16 ***
## factor(year)2016  1.1068e+00  5.0007e-02 22.1335 < 2.2e-16 ***
## factor(year)2017  1.1603e+00  5.1912e-02 22.3513 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_grp_RV_UV) #
stargazer(fe_ind_grp_RV_UV_t, fe_ind_grp_RV_UV_t_i, se = list(se_fe_ind_grp_RV_UV_t, se_fe_ind_grp_RV_UV_t_i), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## =============================================
##                      Dependent variable:     
##                  ----------------------------
##                            log(GRP)          
##                       (1)            (2)     
## ---------------------------------------------
## Rv                   -0.016        -0.016    
##                     (0.029)        (0.029)   
##                                              
## Uv                   -0.015        -0.015    
##                     (0.020)        (0.020)   
##                                              
## log(Inv)            0.135***      0.135***   
##                     (0.027)        (0.027)   
##                                              
## educ                0.00003        0.00003   
##                     (0.0002)      (0.0002)   
##                                              
## Wage                 0.0001        0.0001    
##                     (0.001)        (0.001)   
##                                              
## factor(year)2007                  0.172***   
##                                    (0.015)   
##                                              
## factor(year)2008                  0.329***   
##                                    (0.022)   
##                                              
## factor(year)2009                  0.333***   
##                                    (0.024)   
##                                              
## factor(year)2010                  0.473***   
##                                    (0.028)   
##                                              
## factor(year)2011                  0.633***   
##                                    (0.035)   
##                                              
## factor(year)2012                  0.720***   
##                                    (0.038)   
##                                              
## factor(year)2013                  0.795***   
##                                    (0.041)   
##                                              
## factor(year)2014                  0.882***   
##                                    (0.043)   
##                                              
## factor(year)2015                  0.986***   
##                                    (0.046)   
##                                              
## factor(year)2016                  1.107***   
##                                    (0.050)   
##                                              
## factor(year)2017                  1.160***   
##                                    (0.052)   
##                                              
## ---------------------------------------------
## Observations          943            943     
## =============================================
## Note:             *p<0.1; **p<0.05; ***p<0.01
#no changes
#pFtest(fixed.time, fixed)
#H0 - time effects are unnecessary  
pFtest(fe_ind_grp_RV_UV_t_i, fe_ind_grp_RV_UV)
## 
##  F test for individual effects
## 
## data:  grp_RV_UV_t
## F = 166.82, df1 = 11, df2 = 848, p-value < 2.2e-16
## alternative hypothesis: significant effects
# time effects are needed

#plmtest(fixed, c("time"), type=("bp"))
#H0 - time effects are unnecessary 
plmtest(fe_ind_grp_RV_UV, c("time"), type=("bp"))
## 
##  Lagrange Multiplier Test - time effects (Breusch-Pagan) for unbalanced
##  panels
## 
## data:  grp_RV_UV
## chisq = 100.51, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
# time effects are needed

#so, fe_ind_grp_RV_UV_t is the best model (twoways or individual- we are free to choose)

#Simple models for labour productivity V, without time-effects

ols_plm_labpr_V <- plm(labpr_V, 
               data = long_data, 
               index = c("region", "year"),
               model = "pooling")
cov_ols_plm_labpr_V <- vcovHC(ols_plm_labpr_V, type = "HC0")
se_ols_plm_labpr_V <- sqrt(diag(cov_ols_plm_labpr_V))
coeftest(ols_plm_labpr_V, df = Inf, vcov = cov_ols_plm_labpr_V)
## 
## z test of coefficients:
## 
##                Estimate  Std. Error z value Pr(>|z|)    
## (Intercept) 71.56537228  4.05158322 17.6636  < 2e-16 ***
## V            0.32747799  0.18521070  1.7681  0.07704 .  
## log(Inv)     0.31299588  0.24634909  1.2705  0.20389    
## educ        -0.00055153  0.00091585 -0.6022  0.54704    
## Wage         0.26279519  0.02036891 12.9018  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
fe_ind_labpr_V <- plm(labpr_V, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_labpr_V <- vcovHC(fe_ind_labpr_V, type = "HC0")
se_fe_ind_labpr_V <- sqrt(diag(cov_fe_ind_labpr_V))
coeftest(fe_ind_labpr_V, df = Inf, vcov = cov_fe_ind_labpr_V)
## 
## z test of coefficients:
## 
##           Estimate Std. Error z value  Pr(>|z|)    
## V        1.4289130  0.3345697  4.2709 1.947e-05 ***
## log(Inv) 0.6964646  0.4930316  1.4126    0.1578    
## educ     0.0022717  0.0020270  1.1207    0.2624    
## Wage     0.2354405  0.0291230  8.0843 6.250e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_labpr_V) #
re_labpr_V <- plm(labpr_V, 
              data = long_data, 
              index = c("region", "year"),
              model = "random")
cov_re_labpr_V <- vcovHC(re_labpr_V, type = "HC0")
se_re_labpr_V <- sqrt(diag(cov_re_labpr_V))
coeftest(re_labpr_V, df = Inf, vcov = cov_re_labpr_V)
## 
## z test of coefficients:
## 
##                Estimate  Std. Error z value Pr(>|z|)    
## (Intercept) 71.37332895  4.19830217 17.0005  < 2e-16 ***
## V            0.42285094  0.19406768  2.1789  0.02934 *  
## log(Inv)     0.31967281  0.25320279  1.2625  0.20676    
## educ        -0.00052371  0.00095752 -0.5469  0.58441    
## Wage         0.26079756  0.02088377 12.4880  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#Tests for model for labour productivity V, without time-effects

#Ftest - between fixed effects and pooled OLS
#H0 - pooled OLS are better than fixed effects (because all individual effects are the same)
#H1 - fixed effects are better than pooled OLS ones
pFtest(fe_ind_labpr_V, ols_plm_labpr_V)
## 
##  F test for individual effects
## 
## data:  labpr_V
## F = 1.6496, df1 = 78, df2 = 860, p-value = 0.0005703
## alternative hypothesis: significant effects
#fixed effects are better, as expected
#plmtest - between random effects and pooled OLS
#H0 - pooled OLS are better than random effects (because all random effects are the same - on penal effect)
#H1 - random effects are better than pooled OLS ones
plmtest(ols_plm_labpr_V, type = c('bp'))
## 
##  Lagrange Multiplier Test - (Breusch-Pagan) for unbalanced panels
## 
## data:  labpr_V
## chisq = 5.6025, df = 1, p-value = 0.01793
## alternative hypothesis: significant effects
#random effects are better, but not for sure
#phtest - between fixed effects and random effects
#H0 - random effects are better than fixed effects (random coef. are more efficient)
#H1 - fixed effects are better than random effects (fixed coef. are more efficient)
phtest(fe_ind_labpr_V, re_labpr_V)
## 
##  Hausman Test
## 
## data:  labpr_V
## chisq = 18.874, df = 4, p-value = 0.0008322
## alternative hypothesis: one model is inconsistent
#random effects are then fixed ones - unexpected

#fixed effects are better than random effects
stargazer(ols_plm_labpr_V, fe_ind_labpr_V, re_labpr_V, se = list(se_ols_plm_labpr_V, se_fe_ind_labpr_V, se_re_labpr_V), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## ==========================================
##                   Dependent variable:     
##              -----------------------------
##                          LabPr            
##                 (1)       (2)       (3)   
## ------------------------------------------
## V             0.327*   1.429***   0.423** 
##               (0.185)   (0.335)   (0.194) 
##                                           
## log(Inv)       0.313     0.696     0.320  
##               (0.246)   (0.493)   (0.253) 
##                                           
## educ          -0.001     0.002    -0.001  
##               (0.001)   (0.002)   (0.001) 
##                                           
## Wage         0.263***  0.235***  0.261*** 
##               (0.020)   (0.029)   (0.021) 
##                                           
## ------------------------------------------
## Observations    943       943       943   
## ==========================================
## Note:          *p<0.1; **p<0.05; ***p<0.01

#Extra models with time-effects, LabPr, V

#extra

fe_ind_labpr_V_t <- plm(labpr_V_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "twoways",
              model = "within")
cov_fe_ind_labpr_V_t <- vcovHC(fe_ind_labpr_V_t, type = "HC0")
se_fe_ind_labpr_V_t <- sqrt(diag(cov_fe_ind_labpr_V_t))
coeftest(fe_ind_labpr_V_t, df = Inf, vcov = cov_fe_ind_labpr_V_t)
## 
## z test of coefficients:
## 
##            Estimate Std. Error z value  Pr(>|z|)    
## V        0.04240686 0.35244760  0.1203  0.904229    
## log(Inv) 2.38871058 0.57460650  4.1571 3.223e-05 ***
## educ     0.00067508 0.00275862  0.2447  0.806676    
## Wage     0.08859887 0.03249204  2.7268  0.006395 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_labpr_V) #
#extra

fe_ind_labpr_V_t_i <- plm(labpr_V_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_labpr_V_t_i <- vcovHC(fe_ind_labpr_V_t_i, type = "HC0")
se_fe_ind_labpr_V_t_i <- sqrt(diag(cov_fe_ind_labpr_V_t_i))
coeftest(fe_ind_labpr_V_t_i, df = Inf, vcov = cov_fe_ind_labpr_V_t_i)
## 
## z test of coefficients:
## 
##                     Estimate  Std. Error z value  Pr(>|z|)    
## V                 0.04240686  0.35244760  0.1203  0.904229    
## log(Inv)          2.38871058  0.57460650  4.1571 3.223e-05 ***
## educ              0.00067508  0.00275862  0.2447  0.806676    
## Wage              0.08859887  0.03249204  2.7268  0.006395 ** 
## factor(year)2007  0.65066374  0.53406386  1.2183  0.223100    
## factor(year)2008 -3.09888938  0.60790207 -5.0977 3.438e-07 ***
## factor(year)2009 -8.68869374  0.88373777 -9.8318 < 2.2e-16 ***
## factor(year)2010 -3.35542115  0.65000047 -5.1622 2.441e-07 ***
## factor(year)2011 -1.78934048  0.84549057 -2.1163  0.034316 *  
## factor(year)2012 -4.85969134  0.80684756 -6.0231 1.711e-09 ***
## factor(year)2013 -5.69473355  0.93111669 -6.1160 9.594e-10 ***
## factor(year)2014 -5.03152341  1.01797700 -4.9427 7.706e-07 ***
## factor(year)2015 -6.54828492  0.99398798 -6.5879 4.461e-11 ***
## factor(year)2016 -6.44513062  0.99438505 -6.4815 9.080e-11 ***
## factor(year)2017 -5.47892463  0.94687522 -5.7863 7.194e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_labpr_V) #
stargazer(fe_ind_labpr_V_t, fe_ind_labpr_V_t_i, se = list(se_fe_ind_labpr_V_t, se_fe_ind_labpr_V_t_i), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## =============================================
##                      Dependent variable:     
##                  ----------------------------
##                             LabPr            
##                       (1)            (2)     
## ---------------------------------------------
## V                    0.042          0.042    
##                     (0.352)        (0.352)   
##                                              
## log(Inv)            2.389***      2.389***   
##                     (0.575)        (0.575)   
##                                              
## educ                 0.001          0.001    
##                     (0.003)        (0.003)   
##                                              
## Wage                0.089***      0.089***   
##                     (0.032)        (0.032)   
##                                              
## factor(year)2007                    0.651    
##                                    (0.534)   
##                                              
## factor(year)2008                  -3.099***  
##                                    (0.608)   
##                                              
## factor(year)2009                  -8.689***  
##                                    (0.884)   
##                                              
## factor(year)2010                  -3.355***  
##                                    (0.650)   
##                                              
## factor(year)2011                  -1.789**   
##                                    (0.845)   
##                                              
## factor(year)2012                  -4.860***  
##                                    (0.807)   
##                                              
## factor(year)2013                  -5.695***  
##                                    (0.931)   
##                                              
## factor(year)2014                  -5.032***  
##                                    (1.018)   
##                                              
## factor(year)2015                  -6.548***  
##                                    (0.994)   
##                                              
## factor(year)2016                  -6.445***  
##                                    (0.994)   
##                                              
## factor(year)2017                  -5.479***  
##                                    (0.947)   
##                                              
## ---------------------------------------------
## Observations          943            943     
## =============================================
## Note:             *p<0.1; **p<0.05; ***p<0.01
#no changes
#pFtest(fixed.time, fixed)
#H0 - time effects are unnecessary  
pFtest(fe_ind_labpr_V_t_i, fe_ind_labpr_V)
## 
##  F test for individual effects
## 
## data:  labpr_V_t
## F = 25.455, df1 = 11, df2 = 849, p-value < 2.2e-16
## alternative hypothesis: significant effects
# time effects are needed

#plmtest(fixed, c("time"), type=("bp"))
#H0 - time effects are unnecessary 
plmtest(fe_ind_labpr_V, c("time"), type=("bp"))
## 
##  Lagrange Multiplier Test - time effects (Breusch-Pagan) for unbalanced
##  panels
## 
## data:  labpr_V
## chisq = 1140.2, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
# time effects are needed

#so, fe_ind_labpr_V_t is the best model (twoways or individual- we are free to choose)

#Simple models for labour productivity (RV, UV), without time-effects

ols_plm_labpr_RV_UV <- plm(labpr_RV_UV, 
               data = long_data, 
               index = c("region", "year"),
               model = "pooling")
cov_ols_plm_labpr_RV_UV <- vcovHC(ols_plm_labpr_RV_UV, type = "HC0")
se_ols_plm_labpr_RV_UV <- sqrt(diag(cov_ols_plm_labpr_RV_UV))
coeftest(ols_plm_labpr_RV_UV, df = Inf, vcov = cov_ols_plm_labpr_RV_UV)
## 
## z test of coefficients:
## 
##                Estimate  Std. Error z value  Pr(>|z|)    
## (Intercept) 70.95923239  3.90448072 18.1738 < 2.2e-16 ***
## Rv          -0.34007900  0.23505281 -1.4468  0.147947    
## Uv           0.74840529  0.24796636  3.0182  0.002543 ** 
## log(Inv)     0.36794700  0.23273487  1.5810  0.113885    
## educ        -0.00114385  0.00090255 -1.2674  0.205030    
## Wage         0.25766258  0.02060487 12.5049 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
fe_ind_labpr_RV_UV <- plm(labpr_RV_UV, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_labpr_RV_UV <- vcovHC(fe_ind_labpr_RV_UV, type = "HC0")
se_fe_ind_labpr_RV_UV <- sqrt(diag(cov_fe_ind_labpr_RV_UV))
coeftest(fe_ind_labpr_RV_UV, df = Inf, vcov = cov_fe_ind_labpr_RV_UV)
## 
## z test of coefficients:
## 
##           Estimate Std. Error z value  Pr(>|z|)    
## Rv       1.4334676  0.4694984  3.0532  0.002264 ** 
## Uv       1.4262146  0.5042567  2.8284  0.004679 ** 
## log(Inv) 0.6960052  0.4701780  1.4803  0.138793    
## educ     0.0022750  0.0021546  1.0559  0.291011    
## Wage     0.2354626  0.0300514  7.8353 4.676e-15 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_labpr_RV_UV) #
re_labpr_RV_UV <- plm(labpr_RV_UV, 
              data = long_data, 
              index = c("region", "year"),
              model = "random")
cov_re_labpr_RV_UV <- vcovHC(re_labpr_RV_UV, type = "HC0")
se_re_labpr_RV_UV <- sqrt(diag(cov_re_labpr_RV_UV))
coeftest(re_labpr_RV_UV, df = Inf, vcov = cov_re_labpr_RV_UV)
## 
## z test of coefficients:
## 
##                Estimate  Std. Error z value  Pr(>|z|)    
## (Intercept) 70.78946028  4.04656803 17.4937 < 2.2e-16 ***
## Rv          -0.20054176  0.26652928 -0.7524  0.451799    
## Uv           0.79296876  0.25461874  3.1143  0.001844 ** 
## log(Inv)     0.37022105  0.24056836  1.5389  0.123818    
## educ        -0.00106240  0.00096166 -1.1048  0.269266    
## Wage         0.25680886  0.02113893 12.1486 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#Tests for model for labour productivity (RV, UV), without time-effects

#Ftest - between fixed effects and pooled OLS
#H0 - pooled OLS are better than fixed effects (because all individual effects are the same)
#H1 - fixed effects are better than pooled OLS ones
pFtest(fe_ind_labpr_RV_UV, ols_plm_labpr_RV_UV)
## 
##  F test for individual effects
## 
## data:  labpr_RV_UV
## F = 1.5855, df1 = 78, df2 = 859, p-value = 0.001428
## alternative hypothesis: significant effects
#fixed effects are better, as expected
#plmtest - between random effects and pooled OLS
#H0 - pooled OLS are better than random effects (because all random effects are the same - on penal effect)
#H1 - random effects are better than pooled OLS ones
plmtest(ols_plm_labpr_RV_UV, type = c('bp'))
## 
##  Lagrange Multiplier Test - (Breusch-Pagan) for unbalanced panels
## 
## data:  labpr_RV_UV
## chisq = 3.7675, df = 1, p-value = 0.05226
## alternative hypothesis: significant effects
#random effects are better, but not for sure
#phtest - between fixed effects and random effects
#H0 - random effects are better than fixed effects (random coef. are more efficient)
#H1 - fixed effects are better than random effects (fixed coef. are more efficient)
phtest(fe_ind_labpr_RV_UV, re_labpr_RV_UV)
## 
##  Hausman Test
## 
## data:  labpr_RV_UV
## chisq = 20.452, df = 5, p-value = 0.001028
## alternative hypothesis: one model is inconsistent
#random effects are then fixed ones - unexpected

#fixed effects are better than random effects
stargazer(ols_plm_labpr_RV_UV, fe_ind_labpr_RV_UV, re_labpr_RV_UV, se = list(se_ols_plm_labpr_RV_UV, se_fe_ind_labpr_RV_UV, se_re_labpr_RV_UV), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## ==========================================
##                   Dependent variable:     
##              -----------------------------
##                          LabPr            
##                 (1)       (2)       (3)   
## ------------------------------------------
## Rv            -0.340   1.433***   -0.201  
##               (0.235)   (0.469)   (0.267) 
##                                           
## Uv           0.748***  1.426***  0.793*** 
##               (0.248)   (0.504)   (0.255) 
##                                           
## log(Inv)       0.368     0.696     0.370  
##               (0.233)   (0.470)   (0.241) 
##                                           
## educ          -0.001     0.002    -0.001  
##               (0.001)   (0.002)   (0.001) 
##                                           
## Wage         0.258***  0.235***  0.257*** 
##               (0.021)   (0.030)   (0.021) 
##                                           
## ------------------------------------------
## Observations    943       943       943   
## ==========================================
## Note:          *p<0.1; **p<0.05; ***p<0.01

#Extra models with time-effects, LabPr, RV, UV

#extra

fe_ind_labpr_RV_UV_t <- plm(labpr_RV_UV_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "twoways",
              model = "within")
cov_fe_ind_labpr_RV_UV_t <- vcovHC(fe_ind_labpr_RV_UV_t, type = "HC0")
se_fe_ind_labpr_RV_UV_t <- sqrt(diag(cov_fe_ind_labpr_RV_UV_t))
coeftest(fe_ind_labpr_RV_UV_t, df = Inf, vcov = cov_fe_ind_labpr_RV_UV_t)
## 
## z test of coefficients:
## 
##             Estimate  Std. Error z value  Pr(>|z|)    
## Rv        0.45321644  0.42434893  1.0680  0.285508    
## Uv       -0.21164323  0.51386443 -0.4119  0.680438    
## log(Inv)  2.39026774  0.56764171  4.2109 2.544e-05 ***
## educ      0.00057344  0.00273163  0.2099  0.833725    
## Wage      0.08777297  0.03231192  2.7164  0.006599 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_labpr_RV_UV) #
#extra

fe_ind_labpr_RV_UV_t_i <- plm(labpr_RV_UV_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_labpr_RV_UV_t_i <- vcovHC(fe_ind_labpr_RV_UV_t_i, type = "HC0")
se_fe_ind_labpr_RV_UV_t_i <- sqrt(diag(cov_fe_ind_labpr_RV_UV_t_i))
coeftest(fe_ind_labpr_RV_UV_t_i, df = Inf, vcov = cov_fe_ind_labpr_RV_UV_t_i)
## 
## z test of coefficients:
## 
##                     Estimate  Std. Error z value  Pr(>|z|)    
## Rv                0.45321644  0.42434893  1.0680  0.285508    
## Uv               -0.21164323  0.51386443 -0.4119  0.680438    
## log(Inv)          2.39026774  0.56764171  4.2109 2.544e-05 ***
## educ              0.00057344  0.00273163  0.2099  0.833725    
## Wage              0.08777297  0.03231192  2.7164  0.006599 ** 
## factor(year)2007  0.66645560  0.53257443  1.2514  0.210794    
## factor(year)2008 -3.07903864  0.60369549 -5.1003 3.391e-07 ***
## factor(year)2009 -8.74804826  0.89410172 -9.7842 < 2.2e-16 ***
## factor(year)2010 -3.37514020  0.65133017 -5.1819 2.196e-07 ***
## factor(year)2011 -1.89950619  0.85396601 -2.2243  0.026126 *  
## factor(year)2012 -4.96017257  0.82216315 -6.0331 1.609e-09 ***
## factor(year)2013 -5.78902002  0.94260620 -6.1415 8.174e-10 ***
## factor(year)2014 -5.15598221  1.03625594 -4.9756 6.505e-07 ***
## factor(year)2015 -6.69719311  1.01949948 -6.5691 5.062e-11 ***
## factor(year)2016 -6.62933271  1.03702952 -6.3926 1.631e-10 ***
## factor(year)2017 -5.65652091  0.98485656 -5.7435 9.274e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_labpr_RV_UV) #
stargazer(fe_ind_labpr_RV_UV_t, fe_ind_labpr_RV_UV_t_i, se = list(se_fe_ind_labpr_RV_UV_t, se_fe_ind_labpr_RV_UV_t_i), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## =============================================
##                      Dependent variable:     
##                  ----------------------------
##                             LabPr            
##                       (1)            (2)     
## ---------------------------------------------
## Rv                   0.453          0.453    
##                     (0.424)        (0.424)   
##                                              
## Uv                   -0.212        -0.212    
##                     (0.514)        (0.514)   
##                                              
## log(Inv)            2.390***      2.390***   
##                     (0.568)        (0.568)   
##                                              
## educ                 0.001          0.001    
##                     (0.003)        (0.003)   
##                                              
## Wage                0.088***      0.088***   
##                     (0.032)        (0.032)   
##                                              
## factor(year)2007                    0.666    
##                                    (0.533)   
##                                              
## factor(year)2008                  -3.079***  
##                                    (0.604)   
##                                              
## factor(year)2009                  -8.748***  
##                                    (0.894)   
##                                              
## factor(year)2010                  -3.375***  
##                                    (0.651)   
##                                              
## factor(year)2011                  -1.900**   
##                                    (0.854)   
##                                              
## factor(year)2012                  -4.960***  
##                                    (0.822)   
##                                              
## factor(year)2013                  -5.789***  
##                                    (0.943)   
##                                              
## factor(year)2014                  -5.156***  
##                                    (1.036)   
##                                              
## factor(year)2015                  -6.697***  
##                                    (1.019)   
##                                              
## factor(year)2016                  -6.629***  
##                                    (1.037)   
##                                              
## factor(year)2017                  -5.657***  
##                                    (0.985)   
##                                              
## ---------------------------------------------
## Observations          943            943     
## =============================================
## Note:             *p<0.1; **p<0.05; ***p<0.01
#no changes
#pFtest(fixed.time, fixed)
#H0 - time effects are unnecessary  
pFtest(fe_ind_labpr_RV_UV_t_i, fe_ind_labpr_RV_UV)
## 
##  F test for individual effects
## 
## data:  labpr_RV_UV_t
## F = 25.493, df1 = 11, df2 = 848, p-value < 2.2e-16
## alternative hypothesis: significant effects
# time effects are needed

#plmtest(fixed, c("time"), type=("bp"))
#H0 - time effects are unnecessary 
plmtest(fe_ind_labpr_RV_UV, c("time"), type=("bp"))
## 
##  Lagrange Multiplier Test - time effects (Breusch-Pagan) for unbalanced
##  panels
## 
## data:  labpr_RV_UV
## chisq = 1161.1, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
# time effects are needed

#so, fe_ind_labpr_RV_UV_t is the best model (twoways or individual- we are free to choose)

#Simple models for Empoyment V, without time-effects

ols_plm_emp_V <- plm(emp_V, 
               data = long_data, 
               index = c("region", "year"),
               model = "pooling")
cov_ols_plm_emp_V <- vcovHC(ols_plm_emp_V, type = "HC0")
se_ols_plm_emp_V<- sqrt(diag(cov_ols_plm_emp_V))
coeftest(ols_plm_emp_V, df = Inf, vcov = cov_ols_plm_emp_V)
## 
## z test of coefficients:
## 
##                Estimate  Std. Error z value  Pr(>|z|)    
## (Intercept) -6.5172e-02  1.3831e-02 -4.7121 2.452e-06 ***
## V            9.3934e-04  6.9341e-04  1.3547    0.1755    
## log(Inv)     7.0705e-03  9.8017e-04  7.2136 5.449e-13 ***
## educ        -1.6029e-06  3.9421e-06 -0.4066    0.6843    
## Wage        -7.3659e-07  5.4548e-05 -0.0135    0.9892    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
fe_ind_emp_V <- plm(emp_V, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_emp_V <- vcovHC(fe_ind_emp_V, type = "HC0")
se_fe_ind_emp_V <- sqrt(diag(cov_fe_ind_emp_V))
coeftest(fe_ind_emp_V, df = Inf, vcov = cov_fe_ind_emp_V)
## 
## z test of coefficients:
## 
##             Estimate  Std. Error z value  Pr(>|z|)    
## V         1.7133e-03  8.4138e-04  2.0363   0.04172 *  
## log(Inv)  5.9142e-03  1.1195e-03  5.2829 1.272e-07 ***
## educ     -2.0663e-05  1.0542e-05 -1.9601   0.04998 *  
## Wage      9.9593e-05  4.4418e-05  2.2422   0.02495 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_GDP) #
re_emp_V <- plm(emp_V, 
              data = long_data, 
              index = c("region", "year"),
              model = "random")
cov_re_emp_V <- vcovHC(re_emp_V, type = "HC0")
se_re_emp_V <- sqrt(diag(cov_re_emp_V))
coeftest(re_emp_V, df = Inf, vcov = cov_re_emp_V)
## 
## z test of coefficients:
## 
##                Estimate  Std. Error z value  Pr(>|z|)    
## (Intercept) -6.5691e-02  1.2724e-02 -5.1628 2.433e-07 ***
## V            1.6898e-03  6.1940e-04  2.7281  0.006371 ** 
## log(Inv)     6.5683e-03  8.9824e-04  7.3124 2.623e-13 ***
## educ        -1.4756e-05  8.7369e-06 -1.6890  0.091228 .  
## Wage         8.0667e-05  4.1269e-05  1.9546  0.050625 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#Tests for model for Employment V, without time-effects

#Ftest - between fixed effects and pooled OLS
#H0 - pooled OLS are better than fixed effects (because all individual effects are the same)
#H1 - fixed effects are better than pooled OLS ones
pFtest(fe_ind_emp_V, ols_plm_emp_V)
## 
##  F test for individual effects
## 
## data:  emp_V
## F = 11.42, df1 = 78, df2 = 860, p-value < 2.2e-16
## alternative hypothesis: significant effects
#fixed effects are better, as expected
#plmtest - between random effects and pooled OLS
#H0 - pooled OLS are better than random effects (because all random effects are the same - on penal effect)
#H1 - random effects are better than pooled OLS ones
plmtest(ols_plm_emp_V, type = c('bp'))
## 
##  Lagrange Multiplier Test - (Breusch-Pagan) for unbalanced panels
## 
## data:  emp_V
## chisq = 1002.2, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
#random effects are better, as expected
#phtest - between fixed effects and random effects
#H0 - random effects are better than fixed effects (random coef. are more efficient)
#H1 - fixed effects are better than random effects (fixed coef. are more efficient)
phtest(fe_ind_emp_V, re_emp_V)
## 
##  Hausman Test
## 
## data:  emp_V
## chisq = 13.761, df = 4, p-value = 0.008099
## alternative hypothesis: one model is inconsistent
#random effects are then fixed ones - unexpected

#fixed effects are better than random effects
stargazer(ols_plm_emp_V, fe_ind_emp_V, re_emp_V, se = list(se_ols_plm_emp_V, se_fe_ind_emp_V, se_re_emp_V), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## ===========================================
##                   Dependent variable:      
##              ------------------------------
##                         EmpPerWF           
##                 (1)       (2)        (3)   
## -------------------------------------------
## V              0.001    0.002**   0.002*** 
##               (0.001)   (0.001)    (0.001) 
##                                            
## log(Inv)     0.007***   0.006***  0.007*** 
##               (0.001)   (0.001)    (0.001) 
##                                            
## educ         -0.00000  -0.00002** -0.00001*
##              (0.00000) (0.00001)  (0.00001)
##                                            
## Wage         -0.00000   0.0001**   0.0001* 
##              (0.0001)  (0.00004)  (0.00004)
##                                            
## -------------------------------------------
## Observations    943       943        943   
## ===========================================
## Note:           *p<0.1; **p<0.05; ***p<0.01

#Extra models with time-effects Emp, V

#extra

fe_ind_emp_V_t <- plm(emp_V_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "twoways",
              model = "within")
cov_fe_ind_emp_V_t <- vcovHC(fe_ind_emp_V_t, type = "HC0")
se_fe_ind_emp_V_t <- sqrt(diag(cov_fe_ind_emp_V_t))
coeftest(fe_ind_emp_V_t, df = Inf, vcov = cov_fe_ind_emp_V_t)
## 
## z test of coefficients:
## 
##            Estimate Std. Error z value Pr(>|z|)  
## V        1.3111e-03 7.7438e-04  1.6930  0.09045 .
## log(Inv) 2.2306e-03 2.1646e-03  1.0305  0.30279  
## educ     5.6591e-06 1.3799e-05  0.4101  0.68172  
## Wage     8.9167e-05 5.0471e-05  1.7667  0.07728 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_emp_V) #
#extra

fe_ind_emp_V_t_i <- plm(emp_V_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_emp_V_t_i <- vcovHC(fe_ind_emp_V_t_i, type = "HC0")
se_fe_ind_emp_V_t_i <- sqrt(diag(cov_fe_ind_emp_V_t_i))
coeftest(fe_ind_emp_V_t_i, df = Inf, vcov = cov_fe_ind_emp_V_t_i)
## 
## z test of coefficients:
## 
##                     Estimate  Std. Error z value Pr(>|z|)  
## V                 1.3111e-03  7.7438e-04  1.6930  0.09045 .
## log(Inv)          2.2306e-03  2.1646e-03  1.0305  0.30279  
## educ              5.6591e-06  1.3799e-05  0.4101  0.68172  
## Wage              8.9167e-05  5.0471e-05  1.7667  0.07728 .
## factor(year)2007  1.2508e-03  8.2954e-04  1.5078  0.13160  
## factor(year)2008 -1.1994e-03  1.5033e-03 -0.7979  0.42494  
## factor(year)2009 -9.8623e-04  1.8254e-03 -0.5403  0.58900  
## factor(year)2010  1.0340e-03  1.8081e-03  0.5719  0.56739  
## factor(year)2011  3.5225e-03  2.0945e-03  1.6818  0.09261 .
## factor(year)2012  5.8211e-03  2.5741e-03  2.2614  0.02374 *
## factor(year)2013  7.3621e-03  3.0431e-03  2.4193  0.01555 *
## factor(year)2014  9.0391e-03  3.6630e-03  2.4677  0.01360 *
## factor(year)2015  6.1871e-03  3.6361e-03  1.7015  0.08884 .
## factor(year)2016  7.6130e-03  3.8412e-03  1.9819  0.04749 *
## factor(year)2017  9.5064e-03  3.7157e-03  2.5585  0.01051 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_emp_V) #
stargazer(fe_ind_emp_V_t, fe_ind_emp_V_t_i, se = list(se_fe_ind_emp_V_t, se_fe_ind_emp_V_t_i), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## =============================================
##                      Dependent variable:     
##                  ----------------------------
##                            EmpPerWF          
##                       (1)            (2)     
## ---------------------------------------------
## V                    0.001*        0.001*    
##                     (0.001)        (0.001)   
##                                              
## log(Inv)             0.002          0.002    
##                     (0.002)        (0.002)   
##                                              
## educ                0.00001        0.00001   
##                    (0.00001)      (0.00001)  
##                                              
## Wage                0.0001*        0.0001*   
##                     (0.0001)      (0.0001)   
##                                              
## factor(year)2007                    0.001    
##                                    (0.001)   
##                                              
## factor(year)2008                   -0.001    
##                                    (0.002)   
##                                              
## factor(year)2009                   -0.001    
##                                    (0.002)   
##                                              
## factor(year)2010                    0.001    
##                                    (0.002)   
##                                              
## factor(year)2011                   0.004*    
##                                    (0.002)   
##                                              
## factor(year)2012                   0.006**   
##                                    (0.003)   
##                                              
## factor(year)2013                   0.007**   
##                                    (0.003)   
##                                              
## factor(year)2014                   0.009**   
##                                    (0.004)   
##                                              
## factor(year)2015                   0.006*    
##                                    (0.004)   
##                                              
## factor(year)2016                   0.008**   
##                                    (0.004)   
##                                              
## factor(year)2017                   0.010**   
##                                    (0.004)   
##                                              
## ---------------------------------------------
## Observations          943            943     
## =============================================
## Note:             *p<0.1; **p<0.05; ***p<0.01
#no changes
#pFtest(fixed.time, fixed)
#H0 - time effects are unnecessary  
pFtest(fe_ind_emp_V_t_i, fe_ind_emp_V)
## 
##  F test for individual effects
## 
## data:  emp_V_t
## F = 7.1277, df1 = 11, df2 = 849, p-value = 1.142e-11
## alternative hypothesis: significant effects
# time effects are needed

#plmtest(fixed, c("time"), type=("bp"))
#H0 - time effects are unnecessary 
plmtest(fe_ind_emp_V, c("time"), type=("bp"))
## 
##  Lagrange Multiplier Test - time effects (Breusch-Pagan) for unbalanced
##  panels
## 
## data:  emp_V
## chisq = 58.784, df = 1, p-value = 1.76e-14
## alternative hypothesis: significant effects
# time effects are needed

#so, fe_ind_emp_V_t is the best model (twoways or individual- we are free to choose)

#Simple models for Employment (RV, UV), without time-effects

ols_plm_emp_RV_UV <- plm(emp_RV_UV, 
               data = long_data, 
               index = c("region", "year"),
               model = "pooling")
cov_ols_plm_emp_RV_UV <- vcovHC(ols_plm_emp_RV_UV, type = "HC0")
se_ols_plm_emp_RV_UV<- sqrt(diag(cov_ols_plm_emp_RV_UV))
coeftest(ols_plm_emp_RV_UV, df = Inf, vcov = cov_ols_plm_emp_RV_UV)
## 
## z test of coefficients:
## 
##                Estimate  Std. Error z value  Pr(>|z|)    
## (Intercept) -6.6191e-02  1.3692e-02 -4.8344 1.335e-06 ***
## Rv          -1.8316e-04  1.1141e-03 -0.1644    0.8694    
## Uv           1.6471e-03  1.0332e-03  1.5943    0.1109    
## log(Inv)     7.1629e-03  9.8453e-04  7.2755 3.452e-13 ***
## educ        -2.5989e-06  4.3925e-06 -0.5917    0.5541    
## Wage        -9.3670e-06  5.5666e-05 -0.1683    0.8664    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
fe_ind_emp_RV_UV <- plm(emp_RV_UV, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_emp_RV_UV <- vcovHC(fe_ind_emp_RV_UV, type = "HC0")
se_fe_ind_emp_RV_UV <- sqrt(diag(cov_fe_ind_emp_RV_UV))
coeftest(fe_ind_emp_RV_UV, df = Inf, vcov = cov_fe_ind_emp_RV_UV)
## 
## z test of coefficients:
## 
##             Estimate  Std. Error z value  Pr(>|z|)    
## Rv        1.6988e-03  1.6455e-03  1.0324   0.30187    
## Uv        1.7219e-03  2.0543e-03  0.8382   0.40192    
## log(Inv)  5.9156e-03  9.9665e-04  5.9355 2.929e-09 ***
## educ     -2.0674e-05  1.1847e-05 -1.7450   0.08098 .  
## Wage      9.9523e-05  4.8829e-05  2.0382   0.04153 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_GDP) #
re_emp_RV_UV <- plm(emp_RV_UV, 
              data = long_data, 
              index = c("region", "year"),
              model = "random")
cov_re_emp_RV_UV <- vcovHC(re_emp_RV_UV, type = "HC0")
se_re_emp_RV_UV <- sqrt(diag(cov_re_emp_RV_UV))
coeftest(re_emp_RV_UV, df = Inf, vcov = cov_re_emp_RV_UV)
## 
## z test of coefficients:
## 
##                Estimate  Std. Error z value  Pr(>|z|)    
## (Intercept) -6.6183e-02  1.1520e-02 -5.7449 9.195e-09 ***
## Rv           1.3180e-03  1.4423e-03  0.9138   0.36080    
## Uv           1.9128e-03  1.5689e-03  1.2192   0.22276    
## log(Inv)     6.6057e-03  8.2874e-04  7.9708 1.577e-15 ***
## educ        -1.5025e-05  9.8202e-06 -1.5300   0.12602    
## Wage         7.8667e-05  4.5019e-05  1.7474   0.08057 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#Tests for model for Employment (RV, UV), without time-effects

#Ftest - between fixed effects and pooled OLS
#H0 - pooled OLS are better than fixed effects (because all individual effects are the same)
#H1 - fixed effects are better than pooled OLS ones
pFtest(fe_ind_emp_RV_UV, ols_plm_emp_RV_UV)
## 
##  F test for individual effects
## 
## data:  emp_RV_UV
## F = 11.348, df1 = 78, df2 = 859, p-value < 2.2e-16
## alternative hypothesis: significant effects
#fixed effects are better, as expected
#plmtest - between random effects and pooled OLS
#H0 - pooled OLS are better than random effects (because all random effects are the same - on penal effect)
#H1 - random effects are better than pooled OLS ones
plmtest(ols_plm_emp_RV_UV, type = c('bp'))
## 
##  Lagrange Multiplier Test - (Breusch-Pagan) for unbalanced panels
## 
## data:  emp_RV_UV
## chisq = 992.84, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
#random effects are better, as expected
#phtest - between fixed effects and random effects
#H0 - random effects are better than fixed effects (random coef. are more efficient)
#H1 - fixed effects are better than random effects (fixed coef. are more efficient)
phtest(fe_ind_emp_RV_UV, re_emp_RV_UV)
## 
##  Hausman Test
## 
## data:  emp_RV_UV
## chisq = 13.828, df = 5, p-value = 0.01674
## alternative hypothesis: one model is inconsistent
#random effects are then fixed ones - unexpected

#fixed effects are better than random effects
stargazer(ols_plm_emp_RV_UV, fe_ind_emp_RV_UV, re_emp_RV_UV, se = list(se_ols_plm_emp_RV_UV, se_fe_ind_emp_RV_UV, se_re_emp_RV_UV), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## ==========================================
##                   Dependent variable:     
##              -----------------------------
##                        EmpPerWF           
##                 (1)       (2)       (3)   
## ------------------------------------------
## Rv            -0.0002    0.002     0.001  
##               (0.001)   (0.002)   (0.001) 
##                                           
## Uv             0.002     0.002     0.002  
##               (0.001)   (0.002)   (0.002) 
##                                           
## log(Inv)     0.007***  0.006***  0.007*** 
##               (0.001)   (0.001)   (0.001) 
##                                           
## educ         -0.00000  -0.00002* -0.00002 
##              (0.00000) (0.00001) (0.00001)
##                                           
## Wage         -0.00001  0.0001**   0.0001* 
##              (0.0001)  (0.00005) (0.00005)
##                                           
## ------------------------------------------
## Observations    943       943       943   
## ==========================================
## Note:          *p<0.1; **p<0.05; ***p<0.01

#Extra models with time-effects, emp, RV, UV

#extra

fe_ind_emp_RV_UV_t <- plm(emp_RV_UV_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "twoways",
              model = "within")
cov_fe_ind_emp_RV_UV_t <- vcovHC(fe_ind_emp_RV_UV_t, type = "HC0")
se_fe_ind_emp_RV_UV_t <- sqrt(diag(cov_fe_ind_emp_RV_UV_t))
coeftest(fe_ind_emp_RV_UV_t, df = Inf, vcov = cov_fe_ind_emp_RV_UV_t)
## 
## z test of coefficients:
## 
##             Estimate  Std. Error z value Pr(>|z|)  
## Rv       -4.4930e-04  1.6374e-03 -0.2744  0.78378  
## Uv        2.3997e-03  1.9717e-03  1.2170  0.22359  
## log(Inv)  2.2239e-03  2.1594e-03  1.0299  0.30308  
## educ      6.0946e-06  1.3768e-05  0.4427  0.65801  
## Wage      9.2706e-05  4.9632e-05  1.8679  0.06178 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_emp_RV_UV) #
#extra

fe_ind_emp_RV_UV_t_i <- plm(emp_RV_UV_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_emp_RV_UV_t_i <- vcovHC(fe_ind_emp_RV_UV_t_i, type = "HC0")
se_fe_ind_emp_RV_UV_t_i <- sqrt(diag(cov_fe_ind_emp_RV_UV_t_i))
coeftest(fe_ind_emp_RV_UV_t_i, df = Inf, vcov = cov_fe_ind_emp_RV_UV_t_i)
## 
## z test of coefficients:
## 
##                     Estimate  Std. Error z value Pr(>|z|)  
## Rv               -4.4930e-04  1.6374e-03 -0.2744  0.78378  
## Uv                2.3997e-03  1.9717e-03  1.2170  0.22359  
## log(Inv)          2.2239e-03  2.1594e-03  1.0299  0.30308  
## educ              6.0946e-06  1.3768e-05  0.4427  0.65801  
## Wage              9.2706e-05  4.9632e-05  1.8679  0.06178 .
## factor(year)2007  1.1831e-03  7.7788e-04  1.5210  0.12826  
## factor(year)2008 -1.2845e-03  1.4295e-03 -0.8985  0.36889  
## factor(year)2009 -7.3189e-04  2.0295e-03 -0.3606  0.71838  
## factor(year)2010  1.1185e-03  1.8796e-03  0.5951  0.55177  
## factor(year)2011  3.9946e-03  2.4290e-03  1.6446  0.10006  
## factor(year)2012  6.2517e-03  2.8985e-03  2.1569  0.03101 *
## factor(year)2013  7.7661e-03  3.3581e-03  2.3126  0.02074 *
## factor(year)2014  9.5724e-03  3.9889e-03  2.3998  0.01640 *
## factor(year)2015  6.8252e-03  3.9799e-03  1.7149  0.08636 .
## factor(year)2016  8.4023e-03  4.2754e-03  1.9653  0.04938 *
## factor(year)2017  1.0267e-02  4.1234e-03  2.4900  0.01277 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_emp_RV_UV) #
stargazer(fe_ind_emp_RV_UV_t, fe_ind_emp_RV_UV_t_i, se = list(se_fe_ind_emp_RV_UV_t, se_fe_ind_emp_RV_UV_t_i), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## =============================================
##                      Dependent variable:     
##                  ----------------------------
##                            EmpPerWF          
##                       (1)            (2)     
## ---------------------------------------------
## Rv                  -0.0004        -0.0004   
##                     (0.002)        (0.002)   
##                                              
## Uv                   0.002          0.002    
##                     (0.002)        (0.002)   
##                                              
## log(Inv)             0.002          0.002    
##                     (0.002)        (0.002)   
##                                              
## educ                0.00001        0.00001   
##                    (0.00001)      (0.00001)  
##                                              
## Wage                0.0001*        0.0001*   
##                    (0.00005)      (0.00005)  
##                                              
## factor(year)2007                    0.001    
##                                    (0.001)   
##                                              
## factor(year)2008                   -0.001    
##                                    (0.001)   
##                                              
## factor(year)2009                   -0.001    
##                                    (0.002)   
##                                              
## factor(year)2010                    0.001    
##                                    (0.002)   
##                                              
## factor(year)2011                    0.004    
##                                    (0.002)   
##                                              
## factor(year)2012                   0.006**   
##                                    (0.003)   
##                                              
## factor(year)2013                   0.008**   
##                                    (0.003)   
##                                              
## factor(year)2014                   0.010**   
##                                    (0.004)   
##                                              
## factor(year)2015                   0.007*    
##                                    (0.004)   
##                                              
## factor(year)2016                   0.008**   
##                                    (0.004)   
##                                              
## factor(year)2017                   0.010**   
##                                    (0.004)   
##                                              
## ---------------------------------------------
## Observations          943            943     
## =============================================
## Note:             *p<0.1; **p<0.05; ***p<0.01
#no changes
#pFtest(fixed.time, fixed)
#H0 - time effects are unnecessary  
pFtest(fe_ind_emp_RV_UV_t_i, fe_ind_emp_RV_UV)
## 
##  F test for individual effects
## 
## data:  emp_RV_UV_t
## F = 7.4005, df1 = 11, df2 = 848, p-value = 3.374e-12
## alternative hypothesis: significant effects
# time effects are needed

#plmtest(fixed, c("time"), type=("bp"))
#H0 - time effects are unnecessary 
plmtest(fe_ind_emp_RV_UV, c("time"), type=("bp"))
## 
##  Lagrange Multiplier Test - time effects (Breusch-Pagan) for unbalanced
##  panels
## 
## data:  emp_RV_UV
## chisq = 61.765, df = 1, p-value = 3.87e-15
## alternative hypothesis: significant effects
# time effects are needed

#so, fe_ind_emp_RV_UV_t is the best model (twoways or individual- we are free to choose)

#Simple models for Unemployment V, without time-effects

ols_plm_unemp_V <- plm(unemp_V, 
               data = long_data, 
               index = c("region", "year"),
               model = "pooling")
cov_ols_plm_unemp_V <- vcovHC(ols_plm_unemp_V, type = "HC0")
se_ols_plm_unemp_V <- sqrt(diag(cov_ols_plm_unemp_V))
coeftest(ols_plm_unemp_V, df = Inf, vcov = cov_ols_plm_unemp_V)
## 
## z test of coefficients:
## 
##               Estimate Std. Error z value  Pr(>|z|)    
## (Intercept) 42.7122588 11.0498708  3.8654 0.0001109 ***
## V           -0.8177594  0.7727464 -1.0583 0.2899412    
## log(Inv)    -2.8379332  0.9040166 -3.1392 0.0016938 ** 
## educ        -0.0058946  0.0030306 -1.9450 0.0517714 .  
## Wage         0.0068294  0.0382779  0.1784 0.8583962    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
fe_ind_unemp_V <- plm(unemp_V, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_unemp_V <- vcovHC(fe_ind_unemp_V, type = "HC0")
se_fe_ind_unemp_V <- sqrt(diag(cov_fe_ind_unemp_V))
coeftest(fe_ind_unemp_V, df = Inf, vcov = cov_fe_ind_unemp_V)
## 
## z test of coefficients:
## 
##            Estimate Std. Error z value  Pr(>|z|)    
## V        -0.1905456  0.1341484 -1.4204 0.1554887    
## log(Inv) -1.7786968  0.5296942 -3.3580 0.0007852 ***
## educ      0.0041326  0.0020303  2.0355 0.0418032 *  
## Wage     -0.0383888  0.0132867 -2.8893 0.0038614 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_GDP) #
re_unemp_V <- plm(unemp_V, 
              data = long_data, 
              index = c("region", "year"),
              model = "random")
cov_re_unemp_V <- vcovHC(re_unemp_V, type = "HC0")
se_re_unemp_V <- sqrt(diag(cov_re_unemp_V))
coeftest(re_unemp_V, df = Inf, vcov = cov_re_unemp_V)
## 
## z test of coefficients:
## 
##               Estimate Std. Error z value  Pr(>|z|)    
## (Intercept) 31.5462034  6.4585369  4.8844 1.037e-06 ***
## V           -0.2629284  0.1313009 -2.0025 0.0452324 *  
## log(Inv)    -1.8982017  0.5589742 -3.3959 0.0006841 ***
## educ         0.0033206  0.0021656  1.5333 0.1251928    
## Wage        -0.0356207  0.0139916 -2.5459 0.0109006 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#Tests for model for Unemployment V, without time-effects

#Ftest - between fixed effects and pooled OLS
#H0 - pooled OLS are better than fixed effects (because all individual effects are the same)
#H1 - fixed effects are better than pooled OLS ones
pFtest(fe_ind_unemp_V, ols_plm_unemp_V)
## 
##  F test for individual effects
## 
## data:  unemp_V
## F = 70.489, df1 = 78, df2 = 860, p-value < 2.2e-16
## alternative hypothesis: significant effects
#fixed effects are better, as expected
#plmtest - between random effects and pooled OLS
#H0 - pooled OLS are better than random effects (because all random effects are the same - on penal effect)
#H1 - random effects are better than pooled OLS ones
plmtest(ols_plm_unemp_V, type = c('bp'))
## 
##  Lagrange Multiplier Test - (Breusch-Pagan) for unbalanced panels
## 
## data:  unemp_V
## chisq = 3556.7, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
#random effects are better, as expected
#phtest - between fixed effects and random effects
#H0 - random effects are better than fixed effects (random coef. are more efficient)
#H1 - fixed effects are better than random effects (fixed coef. are more efficient)
phtest(fe_ind_unemp_V, re_unemp_V)
## 
##  Hausman Test
## 
## data:  unemp_V
## chisq = 17.541, df = 4, p-value = 0.001517
## alternative hypothesis: one model is inconsistent
#random effects are then fixed ones - unexpected

#fixed effects are better than random effects
stargazer(ols_plm_unemp_V, fe_ind_unemp_V, re_unemp_V, se = list(se_ols_plm_unemp_V, se_fe_ind_unemp_V, se_re_unemp_V), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## ==========================================
##                   Dependent variable:     
##              -----------------------------
##                          Unemp            
##                 (1)       (2)       (3)   
## ------------------------------------------
## V             -0.818    -0.191   -0.263** 
##               (0.773)   (0.134)   (0.131) 
##                                           
## log(Inv)     -2.838*** -1.779*** -1.898***
##               (0.904)   (0.530)   (0.559) 
##                                           
## educ          -0.006*   0.004**    0.003  
##               (0.003)   (0.002)   (0.002) 
##                                           
## Wage           0.007   -0.038*** -0.036** 
##               (0.038)   (0.013)   (0.014) 
##                                           
## ------------------------------------------
## Observations    943       943       943   
## ==========================================
## Note:          *p<0.1; **p<0.05; ***p<0.01

#Extra models with time-effects, unemp, V

#extra

fe_ind_unemp_V_t <- plm(unemp_V_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "twoways",
              model = "within")
cov_fe_ind_unemp_V_t <- vcovHC(fe_ind_unemp_V_t, type = "HC0")
se_fe_ind_unemp_V_t <- sqrt(diag(cov_fe_ind_unemp_V_t))
coeftest(fe_ind_unemp_V_t, df = Inf, vcov = cov_fe_ind_unemp_V_t)
## 
## z test of coefficients:
## 
##            Estimate Std. Error z value Pr(>|z|)  
## V        -0.0079013  0.1925919 -0.0410  0.96728  
## log(Inv) -1.3707419  0.7435901 -1.8434  0.06527 .
## educ     -0.0043559  0.0039747 -1.0959  0.27312  
## Wage      0.0048148  0.0152795  0.3151  0.75267  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_emp) #
#extra

fe_ind_unemp_V_t_i <- plm(unemp_V_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_unemp_V_t_i <- vcovHC(fe_ind_unemp_V_t_i, type = "HC0")
se_fe_ind_unemp_V_t_i <- sqrt(diag(cov_fe_ind_unemp_V_t_i))
coeftest(fe_ind_unemp_V_t_i, df = Inf, vcov = cov_fe_ind_unemp_V_t_i)
## 
## z test of coefficients:
## 
##                    Estimate Std. Error z value  Pr(>|z|)    
## V                -0.0079013  0.1925919 -0.0410 0.9672750    
## log(Inv)         -1.3707419  0.7435901 -1.8434 0.0652691 .  
## educ             -0.0043559  0.0039747 -1.0959 0.2731207    
## Wage              0.0048148  0.0152795  0.3151 0.7526742    
## factor(year)2007 -0.5758939  0.2769010 -2.0798 0.0375454 *  
## factor(year)2008  0.4571022  0.5711218  0.8004 0.4235031    
## factor(year)2009  2.1544683  0.5844126  3.6866 0.0002273 ***
## factor(year)2010  1.2880364  0.5775992  2.2300 0.0257486 *  
## factor(year)2011  0.5222539  0.6967844  0.7495 0.4535439    
## factor(year)2012 -0.4438067  0.6642352 -0.6681 0.5040398    
## factor(year)2013 -0.6320303  0.6411442 -0.9858 0.3242386    
## factor(year)2014 -1.1290164  0.5825699 -1.9380 0.0526241 .  
## factor(year)2015 -0.8593051  0.6461787 -1.3298 0.1835757    
## factor(year)2016 -0.8784373  0.7186209 -1.2224 0.2215589    
## factor(year)2017 -1.1836659  0.7341363 -1.6123 0.1068914    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_emp) #
stargazer(fe_ind_unemp_V_t, fe_ind_unemp_V_t_i, se = list(se_fe_ind_unemp_V_t, se_fe_ind_unemp_V_t_i), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## =============================================
##                      Dependent variable:     
##                  ----------------------------
##                             Unemp            
##                       (1)            (2)     
## ---------------------------------------------
## V                    -0.008        -0.008    
##                     (0.193)        (0.193)   
##                                              
## log(Inv)            -1.371*        -1.371*   
##                     (0.744)        (0.744)   
##                                              
## educ                 -0.004        -0.004    
##                     (0.004)        (0.004)   
##                                              
## Wage                 0.005          0.005    
##                     (0.015)        (0.015)   
##                                              
## factor(year)2007                  -0.576**   
##                                    (0.277)   
##                                              
## factor(year)2008                    0.457    
##                                    (0.571)   
##                                              
## factor(year)2009                  2.154***   
##                                    (0.584)   
##                                              
## factor(year)2010                   1.288**   
##                                    (0.578)   
##                                              
## factor(year)2011                    0.522    
##                                    (0.697)   
##                                              
## factor(year)2012                   -0.444    
##                                    (0.664)   
##                                              
## factor(year)2013                   -0.632    
##                                    (0.641)   
##                                              
## factor(year)2014                   -1.129*   
##                                    (0.583)   
##                                              
## factor(year)2015                   -0.859    
##                                    (0.646)   
##                                              
## factor(year)2016                   -0.878    
##                                    (0.719)   
##                                              
## factor(year)2017                   -1.184    
##                                    (0.734)   
##                                              
## ---------------------------------------------
## Observations          943            943     
## =============================================
## Note:             *p<0.1; **p<0.05; ***p<0.01
#no changes
#pFtest(fixed.time, fixed)
#H0 - time effects are unnecessary  
pFtest(fe_ind_unemp_V_t_i, fe_ind_unemp_V)
## 
##  F test for individual effects
## 
## data:  unemp_V_t
## F = 14.825, df1 = 11, df2 = 849, p-value < 2.2e-16
## alternative hypothesis: significant effects
# time effects are needed

#plmtest(fixed, c("time"), type=("bp"))
#H0 - time effects are unnecessary 
plmtest(fe_ind_unemp_V, c("time"), type=("bp"))
## 
##  Lagrange Multiplier Test - time effects (Breusch-Pagan) for unbalanced
##  panels
## 
## data:  unemp_V
## chisq = 23.745, df = 1, p-value = 1.1e-06
## alternative hypothesis: significant effects
# time effects are needed

#so, fe_ind_unemp_V_t is the best model (twoways or individual- we are free to choose)

#Simple models for Unemployment (RV, UV), without time-effects

ols_plm_unemp_RV_UV <- plm(unemp_RV_UV, 
               data = long_data, 
               index = c("region", "year"),
               model = "pooling")
cov_ols_plm_unemp_RV_UV <- vcovHC(ols_plm_unemp_RV_UV, type = "HC0")
se_ols_plm_unemp_RV_UV <- sqrt(diag(cov_ols_plm_unemp_RV_UV))
coeftest(ols_plm_unemp_RV_UV, df = Inf, vcov = cov_ols_plm_unemp_RV_UV)
## 
## z test of coefficients:
## 
##               Estimate Std. Error z value  Pr(>|z|)    
## (Intercept) 44.5573476 11.4950675  3.8762 0.0001061 ***
## Rv           1.2142830  0.6145211  1.9760 0.0481567 *  
## Uv          -2.0990614  1.3061676 -1.6070 0.1080460    
## log(Inv)    -3.0052043  0.9484889 -3.1684 0.0015327 ** 
## educ        -0.0040916  0.0025103 -1.6299 0.1031153    
## Wage         0.0224530  0.0425869  0.5272 0.5980347    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
fe_ind_unemp_RV_UV <- plm(unemp_RV_UV, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_unemp_RV_UV <- vcovHC(fe_ind_unemp_RV_UV, type = "HC0")
se_fe_ind_unemp_RV_UV <- sqrt(diag(cov_fe_ind_unemp_RV_UV))
coeftest(fe_ind_unemp_RV_UV, df = Inf, vcov = cov_fe_ind_unemp_RV_UV)
## 
## z test of coefficients:
## 
##            Estimate Std. Error z value  Pr(>|z|)    
## Rv        0.0942017  0.2939824  0.3204 0.7486401    
## Uv       -0.3592402  0.2213856 -1.6227 0.1046557    
## log(Inv) -1.8074166  0.5396089 -3.3495 0.0008096 ***
## educ      0.0043426  0.0020655  2.1025 0.0355137 *  
## Wage     -0.0370065  0.0132800 -2.7866 0.0053259 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_GDP) #
re_unemp_RV_UV <- plm(unemp_RV_UV, 
              data = long_data, 
              index = c("region", "year"),
              model = "random")
cov_re_unemp_RV_UV <- vcovHC(re_unemp_RV_UV, type = "HC0")
se_re_unemp_RV_UV <- sqrt(diag(cov_re_unemp_RV_UV))
coeftest(re_unemp_RV_UV, df = Inf, vcov = cov_re_unemp_RV_UV)
## 
## z test of coefficients:
## 
##               Estimate Std. Error z value  Pr(>|z|)    
## (Intercept) 32.1183492  6.6679175  4.8168 1.458e-06 ***
## Rv           0.1155232  0.2731488  0.4229 0.6723454    
## Uv          -0.4922722  0.2402307 -2.0492 0.0404461 *  
## log(Inv)    -1.9409097  0.5737423 -3.3829 0.0007173 ***
## educ         0.0035726  0.0021777  1.6406 0.1008825    
## Wage        -0.0336379  0.0142364 -2.3628 0.0181366 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#Tests for model for Unemployment (RV, UV), without time-effects

#Ftest - between fixed effects and pooled OLS
#H0 - pooled OLS are better than fixed effects (because all individual effects are the same)
#H1 - fixed effects are better than pooled OLS ones
pFtest(fe_ind_unemp_RV_UV, ols_plm_unemp_RV_UV)
## 
##  F test for individual effects
## 
## data:  unemp_RV_UV
## F = 67.908, df1 = 78, df2 = 859, p-value < 2.2e-16
## alternative hypothesis: significant effects
#fixed effects are better, as expected
#plmtest - between random effects and pooled OLS
#H0 - pooled OLS are better than random effects (because all random effects are the same - on penal effect)
#H1 - random effects are better than pooled OLS ones
plmtest(ols_plm_unemp_RV_UV, type = c('bp'))
## 
##  Lagrange Multiplier Test - (Breusch-Pagan) for unbalanced panels
## 
## data:  unemp_RV_UV
## chisq = 3449, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
#random effects are better, as expected
#phtest - between fixed effects and random effects
#H0 - random effects are better than fixed effects (random coef. are more efficient)
#H1 - fixed effects are better than random effects (fixed coef. are more efficient)
phtest(fe_ind_unemp_RV_UV, re_unemp_RV_UV)
## 
##  Hausman Test
## 
## data:  unemp_RV_UV
## chisq = 22.935, df = 5, p-value = 0.0003473
## alternative hypothesis: one model is inconsistent
#random effects are then fixed ones - unexpected

#fixed effects are better than random effects
stargazer(ols_plm_unemp_RV_UV, fe_ind_unemp_RV_UV, re_unemp_RV_UV, se = list(se_ols_plm_unemp_RV_UV, se_fe_ind_unemp_RV_UV, se_re_unemp_RV_UV), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## ==========================================
##                   Dependent variable:     
##              -----------------------------
##                          Unemp            
##                 (1)       (2)       (3)   
## ------------------------------------------
## Rv            1.214**    0.094     0.116  
##               (0.615)   (0.294)   (0.273) 
##                                           
## Uv            -2.099    -0.359   -0.492** 
##               (1.306)   (0.221)   (0.240) 
##                                           
## log(Inv)     -3.005*** -1.807*** -1.941***
##               (0.948)   (0.540)   (0.574) 
##                                           
## educ          -0.004    0.004**    0.004  
##               (0.003)   (0.002)   (0.002) 
##                                           
## Wage           0.022   -0.037*** -0.034** 
##               (0.043)   (0.013)   (0.014) 
##                                           
## ------------------------------------------
## Observations    943       943       943   
## ==========================================
## Note:          *p<0.1; **p<0.05; ***p<0.01

#Extra models with time-effects, unemp, RV, UV

#extra

fe_ind_unemp_RV_UV_t <- plm(unemp_RV_UV_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "twoways",
              model = "within")
cov_fe_ind_unemp_RV_UV_t <- vcovHC(fe_ind_unemp_RV_UV_t, type = "HC0")
se_fe_ind_unemp_RV_UV_t <- sqrt(diag(cov_fe_ind_unemp_RV_UV_t))
coeftest(fe_ind_unemp_RV_UV_t, df = Inf, vcov = cov_fe_ind_unemp_RV_UV_t)
## 
## z test of coefficients:
## 
##            Estimate Std. Error z value Pr(>|z|)  
## Rv        0.4982158  0.2759034  1.8058  0.07096 .
## Uv       -0.3208908  0.3037499 -1.0564  0.29077  
## log(Inv) -1.3688235  0.7439311 -1.8400  0.06577 .
## educ     -0.0044811  0.0039943 -1.1219  0.26191  
## Wage      0.0037973  0.0151760  0.2502  0.80242  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_emp) #
#extra

fe_ind_unemp_RV_UV_t_i <- plm(unemp_RV_UV_t, 
              data = long_data, 
              index = c("region", "year"),
              effect = "individual",
              model = "within")
cov_fe_ind_unemp_RV_UV_t_i <- vcovHC(fe_ind_unemp_RV_UV_t_i, type = "HC0")
se_fe_ind_unemp_RV_UV_t_i <- sqrt(diag(cov_fe_ind_unemp_RV_UV_t_i))
coeftest(fe_ind_unemp_RV_UV_t_i, df = Inf, vcov = cov_fe_ind_unemp_RV_UV_t_i)
## 
## z test of coefficients:
## 
##                    Estimate Std. Error z value  Pr(>|z|)    
## Rv                0.4982158  0.2759034  1.8058 0.0709555 .  
## Uv               -0.3208908  0.3037499 -1.0564 0.2907713    
## log(Inv)         -1.3688235  0.7439311 -1.8400 0.0657702 .  
## educ             -0.0044811  0.0039943 -1.1219 0.2619135    
## Wage              0.0037973  0.0151760  0.2502 0.8024183    
## factor(year)2007 -0.5564383  0.2809202 -1.9808 0.0476171 *  
## factor(year)2008  0.4815583  0.5795909  0.8309 0.4060533    
## factor(year)2009  2.0813436  0.5685319  3.6609 0.0002513 ***
## factor(year)2010  1.2637426  0.5727740  2.2064 0.0273592 *  
## factor(year)2011  0.3865298  0.6724930  0.5748 0.5654458    
## factor(year)2012 -0.5675995  0.6439334 -0.8815 0.3780706    
## factor(year)2013 -0.7481911  0.6317096 -1.1844 0.2362583    
## factor(year)2014 -1.2823496  0.5954980 -2.1534 0.0312867 *  
## factor(year)2015 -1.0427599  0.6717461 -1.5523 0.1205874    
## factor(year)2016 -1.1053741  0.7587159 -1.4569 0.1451437    
## factor(year)2017 -1.4024644  0.7799962 -1.7980 0.0721707 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fixef(fe_ind_emp) #
stargazer(fe_ind_unemp_RV_UV_t, fe_ind_unemp_RV_UV_t_i, se = list(se_fe_ind_unemp_RV_UV_t, se_fe_ind_unemp_RV_UV_t_i), type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny") #, font.size = "tiny"
## 
## =============================================
##                      Dependent variable:     
##                  ----------------------------
##                             Unemp            
##                       (1)            (2)     
## ---------------------------------------------
## Rv                   0.498*        0.498*    
##                     (0.276)        (0.276)   
##                                              
## Uv                   -0.321        -0.321    
##                     (0.304)        (0.304)   
##                                              
## log(Inv)            -1.369*        -1.369*   
##                     (0.744)        (0.744)   
##                                              
## educ                 -0.004        -0.004    
##                     (0.004)        (0.004)   
##                                              
## Wage                 0.004          0.004    
##                     (0.015)        (0.015)   
##                                              
## factor(year)2007                  -0.556**   
##                                    (0.281)   
##                                              
## factor(year)2008                    0.482    
##                                    (0.580)   
##                                              
## factor(year)2009                  2.081***   
##                                    (0.569)   
##                                              
## factor(year)2010                   1.264**   
##                                    (0.573)   
##                                              
## factor(year)2011                    0.387    
##                                    (0.672)   
##                                              
## factor(year)2012                   -0.568    
##                                    (0.644)   
##                                              
## factor(year)2013                   -0.748    
##                                    (0.632)   
##                                              
## factor(year)2014                  -1.282**   
##                                    (0.595)   
##                                              
## factor(year)2015                   -1.043    
##                                    (0.672)   
##                                              
## factor(year)2016                   -1.105    
##                                    (0.759)   
##                                              
## factor(year)2017                   -1.402*   
##                                    (0.780)   
##                                              
## ---------------------------------------------
## Observations          943            943     
## =============================================
## Note:             *p<0.1; **p<0.05; ***p<0.01
#no changes
#pFtest(fixed.time, fixed)
#H0 - time effects are unnecessary  
pFtest(fe_ind_unemp_RV_UV_t_i, fe_ind_unemp_RV_UV)
## 
##  F test for individual effects
## 
## data:  unemp_RV_UV_t
## F = 15.074, df1 = 11, df2 = 848, p-value < 2.2e-16
## alternative hypothesis: significant effects
# time effects are needed

#plmtest(fixed, c("time"), type=("bp"))
#H0 - time effects are unnecessary 
plmtest(fe_ind_unemp_RV_UV, c("time"), type=("bp"))
## 
##  Lagrange Multiplier Test - time effects (Breusch-Pagan) for unbalanced
##  panels
## 
## data:  unemp_RV_UV
## chisq = 27.991, df = 1, p-value = 1.219e-07
## alternative hypothesis: significant effects
# time effects are needed

#so, fe_ind_unemp_RV_UV_t is the best model (twoways or individual- we are free to choose)

#Stargazer common table

stargazer(fe_ind_grp_V_t, fe_ind_labpr_V_t, fe_ind_emp_V_t, fe_ind_unemp_V_t,  fe_ind_grp_RV_UV_t, fe_ind_labpr_RV_UV_t,fe_ind_emp_RV_UV_t, fe_ind_unemp_RV_UV_t,
          
          se = list(se_fe_ind_grp_V_t, se_fe_ind_labpr_V_t, se_fe_ind_emp_V_t, se_fe_ind_unemp_V_t, se_fe_ind_grp_RV_UV_t, se_fe_ind_labpr_RV_UV_t, se_fe_ind_emp_RV_UV_t, se_fe_ind_unemp_RV_UV_t),
          
          type = "text", omit = c('Constant'), keep.stat = c("n"), font.size = "tiny", title = 'Fixed effects and time effects models', add.lines = list(c('model', 'FE + TE', 'FE + TE', 'FE + TE', 'FE + TE', 'FE + TE', 'FE + TE', 'FE + TE', 'FE + TE')), header=FALSE) #, font.size = "tiny"
## 
## Fixed effects and time effects models
## ====================================================================================
##                                        Dependent variable:                          
##              -----------------------------------------------------------------------
##              log(GRP)  LabPr   EmpPerWF   Unemp  log(GRP)  LabPr   EmpPerWF   Unemp 
##                (1)      (2)       (3)      (4)     (5)      (6)       (7)      (8)  
## ------------------------------------------------------------------------------------
## V             -0.015   0.042    0.001*   -0.008                                     
##              (0.013)  (0.352)   (0.001)  (0.193)                                    
##                                                                                     
## Rv                                                -0.016   0.453    -0.0004  0.498* 
##                                                  (0.029)  (0.424)   (0.002)  (0.276)
##                                                                                     
## Uv                                                -0.015   -0.212    0.002   -0.321 
##                                                  (0.020)  (0.514)   (0.002)  (0.304)
##                                                                                     
## log(Inv)     0.135*** 2.389***   0.002   -1.371* 0.135*** 2.390***   0.002   -1.369*
##              (0.027)  (0.575)   (0.002)  (0.744) (0.027)  (0.568)   (0.002)  (0.744)
##                                                                                     
## educ         0.00003   0.001    0.00001  -0.004  0.00003   0.001    0.00001  -0.004 
##              (0.0002) (0.003)  (0.00001) (0.004) (0.0002) (0.003)  (0.00001) (0.004)
##                                                                                     
## Wage          0.0001  0.089***  0.0001*   0.005   0.0001  0.088***  0.0001*   0.004 
##              (0.001)  (0.032)  (0.0001)  (0.015) (0.001)  (0.032)  (0.00005) (0.015)
##                                                                                     
## ------------------------------------------------------------------------------------
## model        FE + TE  FE + TE   FE + TE  FE + TE FE + TE  FE + TE   FE + TE  FE + TE
## Observations   943      943       943      943     943      943       943      943  
## ====================================================================================
## Note:                                                    *p<0.1; **p<0.05; ***p<0.01