0
votes

I have little experience with panel data in R, and am trying to run a simple panel regression with the plm-package. When converting my dataframe to a pdata.frame, however, my time index-variable is transformed to a factor variable. This means that if I want to regress a dependent variable as a function of time, the regression generates a long list of dummy-variables for time and calculates individual coefficients for each. I just want the average effect per time unit (ie. average monthly increase/decrease in points).

Example dataframe:

ID    Date        Points
1     1/11/2014   2
1     1/12/2014   4
1     1/1/2015    6
1     1/2/2015    8
2     1/11/2014   1
2     1/12/2014   2
2     1/1/2015    3
2     1/2/2015    4

Say the example dataframe structure is ID = int, Date = POSIXct, Points = int. I then convert it to a pdata.frame with index ID and Date:

panel <- pdata.frame(dataframe, c("ID", "Date"))

And run a plm fixed effects regression:

fixed <- plm(Points ~ Date, data=panel, model="within")
summary(fixed)

The resulting coefficients are then broken down by each month as dummies. I want to treat my time-variable as a continuous variable, so I get only one coefficient for Date. How can I do this? Is there a way to avoid formatting the time index-variable as a factor in panel dataframes?

1

1 Answers

2
votes

I think you need to create a separate clock or time counter from panel$Date to use in your model. For example:

library(dplyr)
dataframe <- dataframe %>%
    group_by(ID) %>%
    mutate(clock = seq_along(ID))
panel <- pdata.frame(dataframe, c("ID", "Date"))

That produces these data:

             ID       Date Points clock
1-2014-11-01  1 2014-11-01      2     1
1-2014-12-01  1 2014-12-01      4     2
1-2015-01-01  1 2015-01-01      6     3
1-2015-02-01  1 2015-02-01      8     4
2-2014-11-01  2 2014-11-01      1     1
2-2014-12-01  2 2014-12-01      2     2
2-2015-01-01  2 2015-01-01      3     3
2-2015-02-01  2 2015-02-01      4     4

That produces this output:

> fixed <- plm(Points ~ clock, data=panel, model="within")
> summary(fixed)
Oneway (individual) effect Within Model

Call:
plm(formula = points ~ clock, data = panel, model = "within")

Balanced Panel: n=2, T=4, N=8

Residuals :
   Min. 1st Qu.  Median 3rd Qu.    Max. 
 -0.750  -0.375   0.000   0.375   0.750 

Coefficients :
      Estimate Std. Error t-value Pr(>|t|)   
clock  1.50000    0.22361  6.7082 0.001114 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares:    25
Residual Sum of Squares: 2.5
R-Squared      :  0.9 
      Adj. R-Squared :  0.5625 
F-statistic: 45 on 1 and 5 DF, p-value: 0.0011144