library(wooldridge)
library(rmarkdown)
library(plm)
data("Grunfeld")
head(Grunfeld)
##   firm year   inv  value capital
## 1    1 1935 317.6 3078.5     2.8
## 2    1 1936 391.8 4661.7    52.6
## 3    1 1937 410.6 5387.1   156.9
## 4    1 1938 257.7 2792.2   209.2
## 5    1 1939 330.8 4313.2   203.4
## 6    1 1940 461.2 4643.9   207.2
tail(Grunfeld)
##     firm year  inv value capital
## 195   10 1949 4.21 71.24    7.39
## 196   10 1950 3.42 69.05    8.74
## 197   10 1951 4.67 83.04    9.07
## 198   10 1952 6.00 74.42    9.93
## 199   10 1953 6.53 63.51   11.68
## 200   10 1954 5.12 58.12   14.33
indeks <- pdata.frame(Grunfeld, index = c("firm", "year") )
pdim(indeks)
## Balanced Panel: n = 10, T = 20, N = 200

plm paketi icinde bulunan komut sayesinde veri setinin nelerden olustugunu gorebılmekteyız. Panelde 51 kisi icin 20 yil icinde 200 gozlemi kapsamaktadir.

plm Regresyonu Olusturma

model1 <- plm(inv ~ capital, data = indeks , model= "within" )
summary(model1)
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = inv ~ capital, data = indeks, model = "within")
## 
## Balanced Panel: n = 10, T = 20, N = 200
## 
## Residuals:
##       Min.    1st Qu.     Median    3rd Qu.       Max. 
## -190.71466  -20.83474   -0.45862   21.38262  293.68714 
## 
## Coefficients:
##         Estimate Std. Error t-value  Pr(>|t|)    
## capital 0.370750   0.019368  19.143 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    2244400
## Residual Sum of Squares: 763680
## R-Squared:      0.65973
## Adj. R-Squared: 0.64173
## F-statistic: 366.446 on 1 and 189 DF, p-value: < 2.22e-16

lm Regresyonu

model2<- plm(inv ~ capital, data = indeks )

Regresyonun Ozeti

summary(model2)
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = inv ~ capital, data = indeks)
## 
## Balanced Panel: n = 10, T = 20, N = 200
## 
## Residuals:
##       Min.    1st Qu.     Median    3rd Qu.       Max. 
## -190.71466  -20.83474   -0.45862   21.38262  293.68714 
## 
## Coefficients:
##         Estimate Std. Error t-value  Pr(>|t|)    
## capital 0.370750   0.019368  19.143 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    2244400
## Residual Sum of Squares: 763680
## R-Squared:      0.65973
## Adj. R-Squared: 0.64173
## F-statistic: 366.446 on 1 and 189 DF, p-value: < 2.22e-16

Stargazer

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(model1,model2 ), type="text")
## 
## ======================================================
##                               Dependent variable:     
##                           ----------------------------
##                                       inv             
##                                (1)            (2)     
## ------------------------------------------------------
## capital                      0.371***      0.371***   
##                              (0.019)        (0.019)   
##                                                       
## ------------------------------------------------------
## Observations                   200            200     
## R2                            0.660          0.660    
## Adjusted R2                   0.642          0.642    
## F Statistic (df = 1; 189)   366.446***    366.446***  
## ======================================================
## Note:                      *p<0.1; **p<0.05; ***p<0.01