İleri Panel Veri Yöntemleri

Sabit Etkiler Tahmini

library(plm)
library(wooldridge)
data("cement")

Panel verileri incelemek için lm() komutu yerine plm paketini kullanacağız.Önce plm paketini yükledik, wooldridge paketinden seçtiğimiz datamızı da tanımladık.

head(cement)
##   year month prccem   ipcem prcpet  rresc  rnonc   ip  rdefs milemp gprc
## 1 1964     1     NA 0.47425   13.4 115401 142180 44.6     NA   2687   NA
## 2 1964     2     NA 0.53123   13.4 115118 144190 45.9 1.6634   2696   NA
## 3 1964     3     NA 0.64255   13.4 123663 145577 46.2 1.6626   2693   NA
## 4 1964     4     NA 0.82585   13.4 116178 150793 46.9 1.6626   2694   NA
## 5 1964     5     NA 1.02720   13.4 111034 149259 47.1 1.6610   2690   NA
## 6 1964     6     NA 1.09860   13.4 109138 154347 47.9 1.6601   2687   NA
##         gcem gprcpet        gres         gnon         gip         gdefs
## 1         NA      NA          NA           NA          NA            NA
## 2 0.11346044       0 -0.00245533  0.014038014 0.028731326            NA
## 3 0.19024961       0  0.07160243  0.009573282 0.006514664 -0.0004810665
## 4 0.25096855       0 -0.06243663  0.035202879 0.015037893  0.0000000000
## 5 0.21817875       0 -0.04528704 -0.010224983 0.004255261 -0.0009628278
## 6 0.06720003       0 -0.01722332  0.033520263 0.016842568 -0.0005420073
##         gmilemp jan feb mar apr may jun jul aug sep oct nov dec
## 1            NA   1   0   0   0   0   0   0   0   0   0   0   0
## 2  0.0033438634   0   1   0   0   0   0   0   0   0   0   0   0
## 3 -0.0011133793   0   0   1   0   0   0   0   0   0   0   0   0
## 4  0.0003712641   0   0   0   1   0   0   0   0   0   0   0   0
## 5 -0.0014858844   0   0   0   0   1   0   0   0   0   0   0   0
## 6 -0.0011158640   0   0   0   0   0   1   0   0   0   0   0   0
tail(cement)
##     year month prccem  ipcem prcpet  rresc  rnonc    ip  rdefs milemp
## 307 1989     7   1012 1.1555   59.9 166950 176490 106.0 1.7133   2116
## 308 1989     8   1009 1.2847   53.5 164461 181205 110.5 1.7145     NA
## 309 1989     9   1016 1.1951   56.2 162946 182793 110.9     NA     NA
## 310 1989    10   1017 1.2739   57.6 163195 178832 109.2     NA     NA
## 311 1989    11   1016     NA   57.6 163079 182570 107.7     NA     NA
## 312 1989    12   1017     NA   59.8 163180 182283 106.8     NA     NA
##              gprc        gcem     gprcpet          gres         gnon
## 307  0.0000000000 -0.05169124  0.02707445  0.0005212500 -0.010556582
## 308 -0.0029688296  0.10599206 -0.11299488 -0.0150209060  0.026364770
## 309  0.0069136079 -0.07229543  0.04923512 -0.0092546027  0.008725378
## 310  0.0009837679  0.06385326  0.02460577  0.0015269472 -0.021907547
## 311 -0.0009837679          NA  0.00000000 -0.0007110588  0.020686844
## 312  0.0009837679          NA  0.03748311  0.0006191400 -0.001573237
##              gip        gdefs      gmilemp jan feb mar apr may jun jul aug sep
## 307 -0.037041273 0.0000000000 0.0004727015   0   0   0   0   0   0   1   0   0
## 308  0.041576426 0.0007001347           NA   0   0   0   0   0   0   0   1   0
## 309  0.003613387           NA           NA   0   0   0   0   0   0   0   0   1
## 310 -0.015447873           NA           NA   0   0   0   0   0   0   0   0   0
## 311 -0.013831479           NA           NA   0   0   0   0   0   0   0   0   0
## 312 -0.008391601           NA           NA   0   0   0   0   0   0   0   0   0
##     oct nov dec
## 307   0   0   0
## 308   0   0   0
## 309   0   0   0
## 310   1   0   0
## 311   0   1   0
## 312   0   0   1
head(cement, 10)
##    year month prccem   ipcem prcpet  rresc  rnonc   ip  rdefs milemp gprc
## 1  1964     1     NA 0.47425   13.4 115401 142180 44.6     NA   2687   NA
## 2  1964     2     NA 0.53123   13.4 115118 144190 45.9 1.6634   2696   NA
## 3  1964     3     NA 0.64255   13.4 123663 145577 46.2 1.6626   2693   NA
## 4  1964     4     NA 0.82585   13.4 116178 150793 46.9 1.6626   2694   NA
## 5  1964     5     NA 1.02720   13.4 111034 149259 47.1 1.6610   2690   NA
## 6  1964     6     NA 1.09860   13.4 109138 154347 47.9 1.6601   2687   NA
## 7  1964     7     NA 1.10710   13.4 110492 155871 45.1 1.6601   2696   NA
## 8  1964     8     NA 1.14340   13.4 111540 154130 46.8 1.6582   2693   NA
## 9  1964     9     NA 1.07720   13.4 108353 155359 48.7 1.6567   2690   NA
## 10 1964    10     NA 1.13320   13.4 108173 155020 48.3 1.6567   2680   NA
##            gcem gprcpet         gres         gnon          gip         gdefs
## 1            NA      NA           NA           NA           NA            NA
## 2   0.113460436       0 -0.002455330  0.014038014  0.028731326            NA
## 3   0.190249607       0  0.071602434  0.009573282  0.006514664 -0.0004810665
## 4   0.250968546       0 -0.062436625  0.035202879  0.015037893  0.0000000000
## 5   0.218178749       0 -0.045287035 -0.010224983  0.004255261 -0.0009628278
## 6   0.067200035       0 -0.017223325  0.033520263  0.016842568 -0.0005420073
## 7   0.007707324       0  0.012329984  0.009825428 -0.060233325  0.0000000000
## 8   0.032262247       0  0.009440151 -0.011232340  0.037000973 -0.0011451393
## 9  -0.059641108       0 -0.028988855  0.007942165  0.039795861 -0.0009050111
## 10  0.050680399       0 -0.001662618 -0.002184427 -0.008247501  0.0000000000
##          gmilemp jan feb mar apr may jun jul aug sep oct nov dec
## 1             NA   1   0   0   0   0   0   0   0   0   0   0   0
## 2   0.0033438634   0   1   0   0   0   0   0   0   0   0   0   0
## 3  -0.0011133793   0   0   1   0   0   0   0   0   0   0   0   0
## 4   0.0003712641   0   0   0   1   0   0   0   0   0   0   0   0
## 5  -0.0014858844   0   0   0   0   1   0   0   0   0   0   0   0
## 6  -0.0011158640   0   0   0   0   0   1   0   0   0   0   0   0
## 7   0.0033438634   0   0   0   0   0   0   1   0   0   0   0   0
## 8  -0.0011133793   0   0   0   0   0   0   0   1   0   0   0   0
## 9  -0.0011146202   0   0   0   0   0   0   0   0   1   0   0   0
## 10 -0.0037243990   0   0   0   0   0   0   0   0   0   1   0   0

head() komutu ile cement datasının ilk 6 gözlemine, tail() komutu ile son 6 gözlemine ulaştık. head(cement, 10) komutu ile cement datasının ilk 10 gözlemine ulaştık.

Veri Setini Panel Veri Setine Çevirme

cementindex <-  pdata.frame(cement, index = c("year" , "month" ))
pdim(cementindex)
## Balanced Panel: n = 26, T = 12, N = 312

“plm” Regresyonu ve Özeti

withinmodel <- plm(ipcem ~ prcpet + rresc +factor(year), data = cementindex , model = "within" )
summary(withinmodel)
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = ipcem ~ prcpet + rresc + factor(year), data = cementindex, 
##     model = "within")
## 
## Unbalanced Panel: n = 26, T = 10-12, N = 310
## 
## Residuals:
##      Min.   1st Qu.    Median   3rd Qu.      Max. 
## -0.630808 -0.220949  0.068652  0.208582  0.339675 
## 
## Coefficients:
##          Estimate Std. Error t-value Pr(>|t|)
## prcpet 6.9231e-04 4.0145e-03  0.1725   0.8632
## rresc  2.0774e-06 2.1843e-06  0.9510   0.3424
## 
## Total Sum of Squares:    18.203
## Residual Sum of Squares: 18.145
## R-Squared:      0.0032005
## Adj. R-Squared: -0.092238
## F-statistic: 0.452726 on 2 and 282 DF, p-value: 0.63635

İnterceptli lm Regresyonu ve Özeti

yenimodel <- lm(rresc ~ rnonc + ip +factor(year) , data = cementindex )
summary(yenimodel)
## 
## Call:
## lm(formula = rresc ~ rnonc + ip + factor(year), data = cementindex)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -19549.1  -3336.6   -125.3   3091.5  24263.6 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       6.823e+04  1.520e+04   4.489 1.04e-05 ***
## rnonc             2.514e-02  9.362e-02   0.269 0.788445    
## ip                8.553e+02  1.991e+02   4.296 2.39e-05 ***
## factor(year)1965 -9.326e+03  3.232e+03  -2.885 0.004208 ** 
## factor(year)1966 -2.257e+04  3.955e+03  -5.709 2.87e-08 ***
## factor(year)1967 -2.815e+04  4.045e+03  -6.961 2.34e-11 ***
## factor(year)1968 -1.876e+04  4.481e+03  -4.187 3.78e-05 ***
## factor(year)1969 -1.813e+04  4.739e+03  -3.825 0.000161 ***
## factor(year)1970 -2.264e+04  4.239e+03  -5.341 1.89e-07 ***
## factor(year)1971  3.849e+03  4.254e+03   0.905 0.366313    
## factor(year)1972  2.128e+04  5.045e+03   4.219 3.31e-05 ***
## factor(year)1973  1.401e+04  6.030e+03   2.324 0.020846 *  
## factor(year)1974 -1.762e+04  5.726e+03  -3.078 0.002291 ** 
## factor(year)1975 -3.084e+04  4.677e+03  -6.594 2.08e-10 ***
## factor(year)1976 -1.171e+04  5.709e+03  -2.051 0.041138 *  
## factor(year)1977  8.611e+03  6.891e+03   1.250 0.212449    
## factor(year)1978  1.183e+04  7.480e+03   1.581 0.114929    
## factor(year)1979 -7.987e+02  8.001e+03  -0.100 0.920551    
## factor(year)1980 -3.030e+04  7.703e+03  -3.933 0.000105 ***
## factor(year)1981 -4.263e+04  7.997e+03  -5.331 1.99e-07 ***
## factor(year)1982 -5.758e+04  7.325e+03  -7.860 8.01e-14 ***
## factor(year)1983 -2.376e+04  8.015e+03  -2.964 0.003292 ** 
## factor(year)1984 -7.551e+03  9.343e+03  -0.808 0.419674    
## factor(year)1985 -7.702e+03  9.600e+03  -0.802 0.423063    
## factor(year)1986  1.363e+04  9.759e+03   1.397 0.163485    
## factor(year)1987  1.299e+04  1.064e+04   1.221 0.223067    
## factor(year)1988  1.174e+04  1.165e+04   1.008 0.314383    
## factor(year)1989  2.306e+03  1.216e+04   0.190 0.849678    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6827 on 284 degrees of freedom
## Multiple R-squared:  0.9431, Adjusted R-squared:  0.9377 
## F-statistic: 174.3 on 27 and 284 DF,  p-value: < 2.2e-16

İnterceptsiz lm Regresonu ve Özeti

ikincimodel <- lm(rresc ~ rnonc + ip +factor(year)-1  , data = cementindex )
summary(ikincimodel)
## 
## Call:
## lm(formula = rresc ~ rnonc + ip + factor(year) - 1, data = cementindex)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -19549.1  -3336.6   -125.3   3091.5  24263.6 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## rnonc            2.514e-02  9.362e-02   0.269 0.788445    
## ip               8.553e+02  1.991e+02   4.296 2.39e-05 ***
## factor(year)1964 6.823e+04  1.520e+04   4.489 1.04e-05 ***
## factor(year)1965 5.890e+04  1.682e+04   3.502 0.000536 ***
## factor(year)1966 4.565e+04  1.798e+04   2.539 0.011650 *  
## factor(year)1967 4.007e+04  1.809e+04   2.215 0.027550 *  
## factor(year)1968 4.946e+04  1.862e+04   2.656 0.008350 ** 
## factor(year)1969 5.010e+04  1.883e+04   2.660 0.008261 ** 
## factor(year)1970 4.558e+04  1.815e+04   2.511 0.012580 *  
## factor(year)1971 7.207e+04  1.804e+04   3.995 8.25e-05 ***
## factor(year)1972 8.951e+04  1.854e+04   4.827 2.26e-06 ***
## factor(year)1973 8.224e+04  1.962e+04   4.192 3.70e-05 ***
## factor(year)1974 5.060e+04  1.891e+04   2.676 0.007883 ** 
## factor(year)1975 3.739e+04  1.747e+04   2.140 0.033228 *  
## factor(year)1976 5.651e+04  1.806e+04   3.128 0.001940 ** 
## factor(year)1977 7.684e+04  1.837e+04   4.182 3.85e-05 ***
## factor(year)1978 8.005e+04  1.961e+04   4.081 5.83e-05 ***
## factor(year)1979 6.743e+04  2.041e+04   3.304 0.001075 ** 
## factor(year)1980 3.793e+04  2.032e+04   1.867 0.062989 .  
## factor(year)1981 2.559e+04  2.044e+04   1.252 0.211637    
## factor(year)1982 1.065e+04  1.970e+04   0.541 0.589199    
## factor(year)1983 4.447e+04  1.955e+04   2.275 0.023676 *  
## factor(year)1984 6.067e+04  2.121e+04   2.860 0.004545 ** 
## factor(year)1985 6.052e+04  2.218e+04   2.729 0.006750 ** 
## factor(year)1986 8.186e+04  2.222e+04   3.684 0.000275 ***
## factor(year)1987 8.121e+04  2.282e+04   3.560 0.000435 ***
## factor(year)1988 7.997e+04  2.365e+04   3.381 0.000822 ***
## factor(year)1989 7.053e+04  2.409e+04   2.928 0.003688 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6827 on 284 degrees of freedom
## Multiple R-squared:  0.9975, Adjusted R-squared:  0.9973 
## F-statistic:  4111 on 28 and 284 DF,  p-value: < 2.2e-16

STARGAZER

Stargazer paketi sayesinde elde ettiğimiz tüm regresyonları birleştirdik.

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
stargazer(list(withinmodel, yenimodel, ikincimodel) , type = "text")
## 
## ========================================================================================================
##                                                           Dependent variable:                           
##                                -------------------------------------------------------------------------
##                                       ipcem                                rresc                        
##                                       panel                                 OLS                         
##                                      linear                                                             
##                                        (1)                    (2)                        (3)            
## --------------------------------------------------------------------------------------------------------
## prcpet                                0.001                                                             
##                                      (0.004)                                                            
##                                                                                                         
## rresc                                0.00000                                                            
##                                     (0.00000)                                                           
##                                                                                                         
## rnonc                                                        0.025                      0.025           
##                                                             (0.094)                    (0.094)          
##                                                                                                         
## ip                                                        855.313***                 855.313***         
##                                                            (199.108)                  (199.108)         
##                                                                                                         
## factor(year)1964                                                                    68,225.170***       
##                                                                                     (15,196.690)        
##                                                                                                         
## factor(year)1965                                         -9,325.962***              58,899.210***       
##                                                           (3,232.072)               (16,817.880)        
##                                                                                                         
## factor(year)1966                                        -22,574.670***              45,650.510**        
##                                                           (3,954.568)               (17,979.490)        
##                                                                                                         
## factor(year)1967                                        -28,154.110***              40,071.070**        
##                                                           (4,044.534)               (18,090.370)        
##                                                                                                         
## factor(year)1968                                        -18,762.780***              49,462.390***       
##                                                           (4,481.396)               (18,621.520)        
##                                                                                                         
## factor(year)1969                                        -18,129.190***              50,095.990***       
##                                                           (4,739.414)               (18,833.830)        
##                                                                                                         
## factor(year)1970                                        -22,644.090***              45,581.080**        
##                                                           (4,239.454)               (18,149.650)        
##                                                                                                         
## factor(year)1971                                           3,848.973                72,074.150***       
##                                                           (4,253.725)               (18,041.610)        
##                                                                                                         
## factor(year)1972                                         21,282.910***              89,508.090***       
##                                                           (5,044.774)               (18,541.360)        
##                                                                                                         
## factor(year)1973                                         14,010.900**               82,236.070***       
##                                                           (6,029.502)               (19,617.250)        
##                                                                                                         
## factor(year)1974                                        -17,621.340***              50,603.830***       
##                                                           (5,725.699)               (18,910.050)        
##                                                                                                         
## factor(year)1975                                        -30,839.240***              37,385.940**        
##                                                           (4,676.848)               (17,472.210)        
##                                                                                                         
## factor(year)1976                                         -11,712.400**              56,512.780***       
##                                                           (5,709.272)               (18,064.490)        
##                                                                                                         
## factor(year)1977                                           8,611.452                76,836.630***       
##                                                           (6,890.983)               (18,372.450)        
##                                                                                                         
## factor(year)1978                                          11,827.560                80,052.740***       
##                                                           (7,479.784)               (19,614.830)        
##                                                                                                         
## factor(year)1979                                           -798.709                 67,426.470***       
##                                                           (8,000.819)               (20,406.440)        
##                                                                                                         
## factor(year)1980                                        -30,297.230***               37,927.950*        
##                                                           (7,702.507)               (20,319.360)        
##                                                                                                         
## factor(year)1981                                        -42,632.970***               25,592.200         
##                                                           (7,997.119)               (20,442.740)        
##                                                                                                         
## factor(year)1982                                        -57,577.190***               10,647.990         
##                                                           (7,325.202)               (19,696.200)        
##                                                                                                         
## factor(year)1983                                        -23,759.390***              44,465.790**        
##                                                           (8,015.445)               (19,548.840)        
##                                                                                                         
## factor(year)1984                                          -7,550.737                60,674.440***       
##                                                           (9,343.097)               (21,211.860)        
##                                                                                                         
## factor(year)1985                                          -7,702.213                60,522.960***       
##                                                           (9,600.421)               (22,177.920)        
##                                                                                                         
## factor(year)1986                                          13,633.260                81,858.440***       
##                                                           (9,758.511)               (22,218.420)        
##                                                                                                         
## factor(year)1987                                          12,988.740                81,213.910***       
##                                                          (10,637.060)               (22,815.180)        
##                                                                                                         
## factor(year)1988                                          11,742.830                79,968.000***       
##                                                          (11,651.330)               (23,648.830)        
##                                                                                                         
## factor(year)1989                                           2,306.493                70,531.670***       
##                                                          (12,158.500)               (24,089.180)        
##                                                                                                         
## Constant                                                 68,225.170***                                  
##                                                          (15,196.690)                                   
##                                                                                                         
## --------------------------------------------------------------------------------------------------------
## Observations                           310                    312                        312            
## R2                                    0.003                  0.943                      0.998           
## Adjusted R2                          -0.092                  0.938                      0.997           
## Residual Std. Error (df = 284)                             6,827.354                  6,827.354         
## F Statistic                    0.453 (df = 2; 282) 174.310*** (df = 27; 284) 4,111.449*** (df = 28; 284)
## ========================================================================================================
## Note:                                                                        *p<0.1; **p<0.05; ***p<0.01