last day (15 days later) » 

2:43 PM
0
Q: R: Create panel dataset from time series variables

adrCoderI have a dataset that has the following form: Year ... X1 X2 ... XN ... Y1 Y2 ... Y5 ... 2006 ... 2007 ... 2016 where I run separate regressions for each of the Y's as dependent variables and the X's as the independent variables. I would like to transform this dataset into a panel dataset ...

 
ANG
Your data frame contains a time column/variable (Year). But I don't see any column dedicated to individuals. To create a panel dataset you need both, see here
 
Yes I don't have a unique identifier for my data. But I run separate regressions for each of the Y's. I was thinking if I could somehow run this with panel data fixed effects...
 
ANG
A fixed effects panel regression refers to a regression model in which the group (firms, states, etc.) means are fixed (non-random). If you cannot clearly identify the groups, you cannot use a fixed effect model
 
I have 5 Ys (dependent variables). I could use each of them as one group, meaning having 5 groups in total..
 
ANG
Yes, it's an option. Does this imply that you also have 5 X per row (one for each Y) ?
 
2:43 PM
No I use different X's for the different Y's, so I thought I could somehow transform it into some panel data format... Let me know if you have any ideas/suggestions.
 
ANG
Could you make your example reproducible ?
 
Hi there how are you
Yes just a second
you mean if I can send you the data ?
 
ANG
Fine :) What's about you ?
 
I am fine too thanks
 
ANG
No no, it would be better to add it to your post for the community
 
2:46 PM
I will have to change some data then
names etc.
 
ANG
you can use dput(df), assuming df in the name of your data frame
if you data is big, use something like dput(head(df, 100))
 
structure(list(Year = c(2006, 2007, 2008, 2009, 2010, 2011, 2012,
2013, 2014, 2015, 2016), X1 = c(NA, 6231989.16,
6286192.8, 7997940.88, 5964272.33, 2220471.25, 1161886.38, 1854724.67,
7414435.45, 1030764.86, 1760876.07), X2 = c(NA,
16033423.97, 14591392.59, 10807666.03, 10568403.25, 9895997.3,
7783115.74, 9609331.42, 13195226.51, 9840290.11, 10612093.19),
Y2 = c(NA, NA, NA, 26041118.06,
18038215.91, 19174941.38, 15250404.65, 19670622.34, 19969051.53,
13454512.28, 17033742.37),
Y1 = c(NA, 51860962.74, 38081542.65, 24057388.46, 24340687.5,
I just edit my post and paste that?
 
ANG
I got an error, weird
 
structure(list(Year = c(2006, 2007, 2008, 2009, 2010, 2011, 2012,
2013, 2014, 2015, 2016), X1 = c(NA, 6231989.16,
6286192.8, 7997940.88, 5964272.33, 2220471.25, 1161886.38, 1854724.67,
7414435.45, 1030764.86, 1760876.07), X2 = c(NA,
16033423.97, 14591392.59, 10807666.03, 10568403.25, 9895997.3,
7783115.74, 9609331.42, 13195226.51, 9840290.11, 10612093.19),
Y2 = c(NA, NA, NA, 26041118.06,
18038215.91, 19174941.38, 15250404.65, 19670622.34, 19969051.53,
13454512.28, 17033742.37),
Y1 = c(NA, 51860962.74, 38081542.65, 24057388.46, 24340687.5,
dose this work?
*does
 
ANG
3:02 PM
Error: unexpected '<' in:
" )), row.names = c(NA, -11L), class = c("data.table",
"data.frame"), .internal.selfref = <"
anyway, I was able to re-create df
df <- data.frame(year = 2006:2016,
X1 = c(NA, 6231989.16,
6286192.8, 7997940.88, 5964272.33, 2220471.25, 1161886.38, 1854724.67,
7414435.45, 1030764.86, 1760876.07),
X2 = c(NA,
16033423.97, 14591392.59, 10807666.03, 10568403.25, 9895997.3,
7783115.74, 9609331.42, 13195226.51, 9840290.11, 10612093.19),
Y2 = c(NA, NA, NA, 26041118.06,
18038215.91, 19174941.38, 15250404.65, 19670622.34, 19969051.53,
13454512.28, 17033742.37),
Y1 = c(NA, 51860962.74, 38081542.65, 24057388.46, 24340687.5,
27960591.55, 25526505.72, 31599623.65, 38597641.61, 48611516.44,
just check de output if it's ok
*the
 
It looks ok
 
ANG
Ok, I will post an answer but we might have some issues. Do not hesitate to add your comments
 
3:30 PM
ok sure thanks
I replied
how can I use different names for the variables?
Because in my real dataset I have other variable names and not X1 X2 Y1 Y2 etc.
 

last day (15 days later) »