1

I am working on a Panel Data that spans from 3rd February 2020 to 29th May 2020. In order to test my hypotheses, I need to run the same regression on the whole period and additionally on 3 different time periods:

  1. 03.02.2020 to 21.02.2020
  2. 24.02.2020 to 10.04.2020
  3. 13.04.2020 to 29.05.2020

Is there an easy way to do it in R? I am using the plm package to run a Pooled OLS regression and subsequently I will also need to run a regression for Difference-in-Differences. My data is structured as follows:

ID Date Independent variables
1 2020.02.03 ...
1 2020.02.04 ...
1 ... ...
1 2020.05.29 ...
2 2020.02.03 ...
2 2020.02.04 ...
... ... ...

I have no clue on how to break down the regression for the timestamps specified. I know only how to run the regression for the entire time period.

genistae
  • 21
  • 2
  • This does not seem to be plm specific. Just use the usual subsetting for data frames and run seperate regressions on the various separate data frames you created this way. For a total of 4 data frames (full set and 3 subsets), I suggest to do it manually. – Helix123 Dec 08 '22 at 18:27

1 Answers1

0

As commentor suggest any form of subsetting would do. Here is a tidyverse-way where you filter inside the plm regression.

library(plm)
library(tidyverse)
library(stargazer)

model_plm_all <- plm(pcap ~ unemp + water + util + pc + gsp, 
                 data=Produc, 
                 effect = "individual", model = "within", 
                 index=c("state", "year"))

model_plm_region5 <- plm(pcap ~ unemp + water + util + pc + gsp, 
                 data=Produc %>%filter(region == 5), 
                 effect = "individual", model = "within", 
                 index=c("state", "year"))

model_plm_region6 <- plm(pcap ~ unemp + water + util + pc + gsp, 
                         data=Produc %>%filter(region == 6), 
                         effect = "individual", model = "within", 
                         index=c("state", "year"))

stargazer(model_plm_all, model_plm_region5, model_plm_region6, type="text",
          column.labels = c("All", "Region 5", "Region 6"), model.numbers = FALSE)

==========================================================================================
                                          Dependent variable:                             
             -----------------------------------------------------------------------------
                                                 pcap                                     
                        All                      Region 5                 Region 6        
------------------------------------------------------------------------------------------
unemp                92.486***                  94.759***                   4.667         
                      (11.648)                   (23.912)                 (27.650)        
                                                                                          
water                 0.759***                   1.110***                  0.637**        
                      (0.040)                    (0.155)                   (0.284)        
                                                                                          
util                  1.316***                   1.193***                 0.730***        
                      (0.017)                    (0.066)                   (0.149)        
                                                                                          
pc                     0.006                     0.039**                  0.127***        
                      (0.004)                    (0.017)                   (0.030)        
                                                                                          
gsp                    0.006                      0.001                    -0.022         
                      (0.004)                    (0.015)                   (0.029)        
                                                                                          
------------------------------------------------------------------------------------------
Observations            816                        136                       68           
R2                     0.970                      0.984                     0.960         
Adjusted R2            0.968                      0.982                     0.954         
F Statistic  4,899.365*** (df = 5; 763) 1,511.193*** (df = 5; 123) 280.529*** (df = 5; 59)
==========================================================================================
Note:                                                          *p<0.1; **p<0.05; ***p<0.01
Marco
  • 2,368
  • 6
  • 22
  • 48