project

Comparison of models

The first problem

brumn_dat <- read.dta13('datasets/brumm.dta')
ivmodel <- ivreg(inflat ~ output+money|initial +school+inv+poprate+money, data = brumn_dat)

stargazer(ivmodel, type = 'text')
## 
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                               inflat           
## -----------------------------------------------
## output                       -1.394**          
##                               (0.552)          
##                                                
## money                        1.035***          
##                               (0.010)          
##                                                
## Constant                      -1.094           
##                               (1.858)          
##                                                
## -----------------------------------------------
## Observations                    76             
## R2                             0.995           
## Adjusted R2                    0.995           
## Residual Std. Error       4.344 (df = 73)      
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
summary(ivmodel)
## 
## Call:
## ivreg(formula = inflat ~ output + money | initial + school + 
##     inv + poprate + money, data = brumn_dat)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -24.633  -1.487   0.204   1.937   9.498 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.093985   1.858208  -0.589   0.5579    
## output      -1.394200   0.551503  -2.528   0.0136 *  
## money        1.035059   0.009773 105.914   <2e-16 ***
## 
## Diagnostic tests:
##                  df1 df2 statistic p-value   
## Weak instruments   4  70     4.642 0.00221 **
## Wu-Hausman         1  72     0.300 0.58551   
## Sargan             3  NA     2.455 0.48344   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.344 on 73 degrees of freedom
## Multiple R-Squared: 0.9947,  Adjusted R-squared: 0.9946 
## Wald test:  6852 on 2 and 73 DF,  p-value: < 2.2e-16

The second problem

income_democracy_dat <- read.dta13('datasets/income_democracy.dta')
income_democracy_dat.p <- pdata.frame(income_democracy_dat, index = c("code","year"))
# 检查面板数据是否平衡
balance_res <- pdim(income_democracy_dat.p)


# 查找数据
t.a <- dplyr::filter(income_democracy_dat, country == "United States", year == 2000) $ dem_ind
kable(t.a, caption = "US and year = 2000")
US and year = 2000
x
1
t.a2 <- mean(dplyr::filter(income_democracy_dat, country == "United States") $ dem_ind)
kable(t.a2, caption = "US average of dem_ind")
US average of dem_ind
x
0.9855556
t.libya <- dplyr::filter(income_democracy_dat, country == "Libya", year == 2000) $ dem_ind
kable(t.libya, caption = "Libya and year = 2000")
Libya and year = 2000
x
0
t.libya2 <- mean(dplyr::filter(income_democracy_dat, country == "Libya") $ dem_ind)
kable(t.libya2, caption = "Libya average of dem_ind")
Libya average of dem_ind
x
0.1092593
# 2b
income_democracy1 <- income_democracy_dat %>% 
  group_by(code) %>% 
  summarise(
    mean_dem_ind = mean(dem_ind, na.rm = TRUE)
  )
income_democracy2 <- full_join(income_democracy_dat, income_democracy1, by = "code")

income_democracy3 <-  distinct(income_democracy2, code, mean_dem_ind, .keep_all = TRUE) %>% 
  arrange(mean_dem_ind)

list_5.1 <- dplyr::filter(income_democracy3, mean_dem_ind > 0.95) $ country %>% head(n=5)
list_5.2 <- dplyr::filter(income_democracy3, mean_dem_ind < 0.10) $ country %>% head(n=5)
list_5.3 <- dplyr::filter(income_democracy3, mean_dem_ind > 0.3,
              mean_dem_ind < 0.7) $ country %>% head(n=5)

kable(list_5.1, caption = ">0.95 Five countries")
>0.95 Five countries
x
Malta
Luxembourg
Germany, West
Japan
Costa Rica
kable(list_5.2, caption = "<0.10 Five countries")
<0.10 Five countries
x
Eritrea
Turkmenistan
Uzbekistan
Vietnam
Equatorial Guinea
kable(list_5.3, caption = "[0.3,0.7] Five countries")
[0.3,0.7] Five countries
x
Zimbabwe
Jordan
Nigeria
Bulgaria
Bosnia and Herzegovina

3.回归分析

md3 <- lm(dem_ind ~ log_gdppc, data=income_democracy_dat)
md3.reg <- coef_test(md3, vcov='CR2', cluster = income_democracy_dat$country)
stargazer(md3.reg, type = 'text')
## 
## ============================================================
## Statistic N  Mean  St. Dev.   Min   Pctl(25) Pctl(75)  Max  
## ------------------------------------------------------------
## beta      2 -0.560  1.125   -1.355   -0.957   -0.162  0.236 
## SE        2 0.056   0.063    0.012   0.034    0.079   0.101 
## tstat     2 3.191   23.487  -13.417  -5.113   11.495  19.799
## df        2 69.863  0.845   69.266   69.564   70.162  70.461
## p_Satt    2 0.000   0.000      0       0        0       0   
## ------------------------------------------------------------
# 3(b)
est <- md3$coefficients[1] + 0.2 * md3$coefficients[2]

kable(est, caption = "dem_ind result")
dem_ind result
x
(Intercept) -1.307693
are <- confint(md3, level = 0.95)[1,] + 0.2 * confint(md3, 'log_gdppc', level=0.95)
kable(are, caption = '95% interval')
95% interval
2.5 % 97.5 %
log_gdppc -1.450253 -1.165133

4.回归分析

固定效应模型(a)
regfeind <- plm(dem_ind ~ log_gdppc, data = income_democracy_dat, effect = "individual")
stargazer(regfeind, type = 'text')
## 
## ========================================
##                  Dependent variable:    
##              ---------------------------
##                        dem_ind          
## ----------------------------------------
## log_gdppc             0.084***          
##                        (0.021)          
##                                         
## ----------------------------------------
## Observations             958            
## R2                      0.020           
## Adjusted R2            -0.163           
## F Statistic    16.202*** (df = 1; 807)  
## ========================================
## Note:        *p<0.1; **p<0.05; ***p<0.01
est4.a <- 0.2 * regfeind$coefficients
kable(est4.a, caption = "dem_ind result in 4(a)")
dem_ind result in 4(a)
x
log_gdppc 0.0167482
are4.a <- 0.2*confint(regfeind, 'log_gdppc', level = 0.95)
kable(are4.a, caption = '95% interval in 4(a)')
95% interval in 4(a)
2.5 % 97.5 %
log_gdppc 0.0085929 0.0249035
固定效应模型(b)
dat <- dplyr::filter(income_democracy_dat, country != "Azerbaijan")
no_a_md <- plm(dem_ind ~ log_gdppc, data = dat, effect = "individual")

stargazer(no_a_md,type = 'text')
## 
## ========================================
##                  Dependent variable:    
##              ---------------------------
##                        dem_ind          
## ----------------------------------------
## log_gdppc             0.084***          
##                        (0.021)          
##                                         
## ----------------------------------------
## Observations             957            
## R2                      0.020           
## Adjusted R2            -0.161           
## F Statistic    16.202*** (df = 1; 807)  
## ========================================
## Note:        *p<0.1; **p<0.05; ***p<0.01
est4.b <- 0.2 * no_a_md$coefficients
kable(est4.b, caption = "dem_ind result in 4(b)")
dem_ind result in 4(b)
x
log_gdppc 0.0167482
are4.b <- 0.2*confint(no_a_md, 'log_gdppc', level = 0.95)
kable(are4.b, caption = '95% interval in 4(b)')
95% interval in 4(b)
2.5 % 97.5 %
log_gdppc 0.0085929 0.0249035
固定效应模型(c)
two_fixed_md <- plm(dem_ind ~ log_gdppc, data = income_democracy_dat, effect = "time")

stargazer(two_fixed_md,type = 'text')
## 
## ========================================
##                  Dependent variable:    
##              ---------------------------
##                        dem_ind          
## ----------------------------------------
## log_gdppc             0.235***          
##                        (0.008)          
##                                         
## ----------------------------------------
## Observations             958            
## R2                      0.449           
## Adjusted R2             0.444           
## F Statistic   772.299*** (df = 1; 948)  
## ========================================
## Note:        *p<0.1; **p<0.05; ***p<0.01
est4.c <- 0.2 * two_fixed_md$coefficients
kable(est4.c, caption = "dem_ind result in 4(c)")
dem_ind result in 4(c)
x
log_gdppc 0.0470213
are4.c <- 0.2*confint(two_fixed_md, 'log_gdppc', level = 0.95)
kable(are4.c, caption = '95% interval in 4(c)')
95% interval in 4(c)
2.5 % 97.5 %
log_gdppc 0.0437051 0.0503376
固定效应模型(d)
two_variable_md <- plm(dem_ind ~ log_gdppc+log_pop, data = income_democracy_dat, effect = "twoway")

stargazer(two_variable_md, type = 'text')
## 
## ========================================
##                  Dependent variable:    
##              ---------------------------
##                        dem_ind          
## ----------------------------------------
## log_gdppc               0.006           
##                        (0.032)          
##                                         
## log_pop                -0.093           
##                        (0.066)          
##                                         
## ----------------------------------------
## Observations             895            
## R2                      0.003           
## Adjusted R2            -0.209           
## F Statistic      1.240 (df = 2; 737)    
## ========================================
## Note:        *p<0.1; **p<0.05; ***p<0.01
est4.d <- 0.2 * two_variable_md$coefficients
kable(est4.d, caption = "dem_ind result in 4(d)")
dem_ind result in 4(d)
x
log_gdppc 0.0012078
log_pop -0.0185721
are4.d <- 0.2*confint(two_variable_md, 'log_gdppc', level = 0.95)
kable(are4.d, caption = '95% interval in 4(d)')
95% interval in 4(d)
2.5 % 97.5 %
log_gdppc -0.0113089 0.0137245
固定效应模型(e)
two_variable_md2 <- plm(dem_ind ~ log_gdppc+educ, data = income_democracy_dat, effect = "twoway")

stargazer(two_variable_md2, type = 'text')
## 
## ========================================
##                  Dependent variable:    
##              ---------------------------
##                        dem_ind          
## ----------------------------------------
## log_gdppc               0.019           
##                        (0.037)          
##                                         
## educ                   -0.007           
##                        (0.017)          
##                                         
## ----------------------------------------
## Observations             688            
## R2                      0.001           
## Adjusted R2            -0.180           
## F Statistic      0.166 (df = 2; 582)    
## ========================================
## Note:        *p<0.1; **p<0.05; ***p<0.01
est4.e <- 0.2 * two_variable_md2$coefficients
kable(est4.e, caption = "dem_ind result in 4(e)")
dem_ind result in 4(e)
x
log_gdppc 0.0037077
educ -0.0014747
are4.e <- 0.2*confint(two_variable_md2, 'log_gdppc', level = 0.95)
kable(are4.e, caption = '95% interval in 4(e)')
95% interval in 4(e)
2.5 % 97.5 %
log_gdppc -0.0107379 0.0181533