How to run a time series model on panel data?
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
-
- Posts: 12
- Joined: Mon Jan 29, 2018 9:57 am
How to run a time series model on panel data?
Hello,
I have financial data of 40+ companies for 20+ years in an excel sheet. What I want to do is run a few time series regressions and tests (1. log(y)= c + b1*(log(y(-1))); 2. log(y)= c + b1*(log(y(-1))) + b2*x; Dickey Fuller for log(y(-1))).
How do I most easily do this for all 40+ companies without manually running these regressions (and tests) over and over again for each of the companies? Can I use the "for" command? (Each company has a GVKEY (a number) associated with it (not from 1-n (e.g. GVKEY(Comp#1)=11409 GVKEY(Comp#2)= 15668, etc)).
I know that my data looks like a panel but I am only interest in time-series models (but for all of the individuals (companies)).
I am using EViews 9.5 standard version.
I apologize if anything doesn't make sense... first time posting.
Mihailo Savic.
I have financial data of 40+ companies for 20+ years in an excel sheet. What I want to do is run a few time series regressions and tests (1. log(y)= c + b1*(log(y(-1))); 2. log(y)= c + b1*(log(y(-1))) + b2*x; Dickey Fuller for log(y(-1))).
How do I most easily do this for all 40+ companies without manually running these regressions (and tests) over and over again for each of the companies? Can I use the "for" command? (Each company has a GVKEY (a number) associated with it (not from 1-n (e.g. GVKEY(Comp#1)=11409 GVKEY(Comp#2)= 15668, etc)).
I know that my data looks like a panel but I am only interest in time-series models (but for all of the individuals (companies)).
I am using EViews 9.5 standard version.
I apologize if anything doesn't make sense... first time posting.
Mihailo Savic.
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13317
- Joined: Tue Sep 16, 2008 5:38 pm
Re: How to run a time series model on panel data?
Yes, you can use a for loop to do this. Take a read through some of the programming guides and you should be set.
viewtopic.php?f=5&t=1638
http://www.eviews.com/Learning/programming.html
viewtopic.php?f=5&t=1638
http://www.eviews.com/Learning/programming.html
Follow us on Twitter @IHSEViews
-
- Posts: 12
- Joined: Mon Jan 29, 2018 9:57 am
Re: How to run a time series model on panel data?
Thank you Gareth,
Would you mind being more specific as to how I would do this. How do I tell the program to check through the GVKEYs? Also will it still run the regression for all y and y(-1) each time (which I don't want it to do) or just for the ones that are associated with one GVKEY?
Mihailo.
Would you mind being more specific as to how I would do this. How do I tell the program to check through the GVKEYs? Also will it still run the regression for all y and y(-1) each time (which I don't want it to do) or just for the ones that are associated with one GVKEY?
Mihailo.
-
- Posts: 12
- Joined: Mon Jan 29, 2018 9:57 am
Re: How to run a time series model on panel data?
I believe I figured out how to calculate what I need, but I am still having trouble exporting all of the results to an excel sheet. I want the excel sheet to contain The GVKEY Company name coefficients for all of my variables (and intercept), the t values, adjusted R^2, SE, and the t stat from the ADF.
Here is the code:
matrix ((@rows(gvkey))/33,2) ys_adf
scalar rows=@rows(gvkey)
scalar i=1
scalar j=1
while i<rows
scalar gvk=gvkey(i)
smpl if gvkey=gvk
series y{gvk}=log(adjusted_oibdp)
series x{gvk}=log(capital_expenditures)
equation eq{gvk}.ls y{gvk} c y{gvk}(-1)
equation eq{gvk}x.ls y{gvk} c y{gvk}(-1) x{gvk}
equation eq{gvk}tr.ls y{gvk} c y{gvk}(-1) x{gvk} @trend
freeze(adftable) y{gvk}.uroot(adf)
ys_adf(j,1)= gvk
ys_adf(j,2)= @val(adftable(7,4))
d adftable
while i<rows and gvk=gvkey(i)
i=i+1
wend
j=j+1
wend
How do I export all these results to an Excel sheet?
Mihailo.
Here is the code:
matrix ((@rows(gvkey))/33,2) ys_adf
scalar rows=@rows(gvkey)
scalar i=1
scalar j=1
while i<rows
scalar gvk=gvkey(i)
smpl if gvkey=gvk
series y{gvk}=log(adjusted_oibdp)
series x{gvk}=log(capital_expenditures)
equation eq{gvk}.ls y{gvk} c y{gvk}(-1)
equation eq{gvk}x.ls y{gvk} c y{gvk}(-1) x{gvk}
equation eq{gvk}tr.ls y{gvk} c y{gvk}(-1) x{gvk} @trend
freeze(adftable) y{gvk}.uroot(adf)
ys_adf(j,1)= gvk
ys_adf(j,2)= @val(adftable(7,4))
d adftable
while i<rows and gvk=gvkey(i)
i=i+1
wend
j=j+1
wend
How do I export all these results to an Excel sheet?
Mihailo.
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13317
- Joined: Tue Sep 16, 2008 5:38 pm
Re: How to run a time series model on panel data?
Probably the best way would be to store them into an EViews table or matrix, then save that table or matrix as a .csv file, then open in Excel.
Follow us on Twitter @IHSEViews
-
- Posts: 12
- Joined: Mon Jan 29, 2018 9:57 am
Re: How to run a time series model on panel data?
Thank you!
I "freeze"d the adftable and put it into a matrix and then exported it like you said. It worked.
But how do I freeze the equations of my ls equations? What is the command to freeze them to build the matrices?
I "freeze"d the adftable and put it into a matrix and then exported it like you said. It worked.
But how do I freeze the equations of my ls equations? What is the command to freeze them to build the matrices?
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13317
- Joined: Tue Sep 16, 2008 5:38 pm
Re: How to run a time series model on panel data?
For the equations you can pull off the stats you want directly without freezing.
All the other data members for equations can be found in the Equation section of the Object Reference:
http://www.eviews.com/help/helpintro.ht ... uation_aic
Code: Select all
table mytable
mytable(gvk,1) = eq{gvk}.@r2
All the other data members for equations can be found in the Equation section of the Object Reference:
http://www.eviews.com/help/helpintro.ht ... uation_aic
Follow us on Twitter @IHSEViews
-
- Posts: 12
- Joined: Mon Jan 29, 2018 9:57 am
Re: How to run a time series model on panel data?
Thank you again!
One more question, for some reason I cannot see any of the residuals on the equations that I get. Number of obs per company should be 31 (as the results properly show) but the residuals show nothing and it says that the number of obs for residuals is 983 (which is as if it is not looking only at just one company like I told it to).
Mihailo.
One more question, for some reason I cannot see any of the residuals on the equations that I get. Number of obs per company should be 31 (as the results properly show) but the residuals show nothing and it says that the number of obs for residuals is 983 (which is as if it is not looking only at just one company like I told it to).
Mihailo.
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13317
- Joined: Tue Sep 16, 2008 5:38 pm
Re: How to run a time series model on panel data?
What exactly are you looking at/doing?
Follow us on Twitter @IHSEViews
-
- Posts: 12
- Joined: Mon Jan 29, 2018 9:57 am
Re: How to run a time series model on panel data?
For the code that I wrote (calculate ls y c y(-1) x... per company) I get my equations for each of the companies. I open the results (object) and everything is there, but when I look at the "Resids" tab in the object it doesn't show me anything.
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13317
- Joined: Tue Sep 16, 2008 5:38 pm
Re: How to run a time series model on panel data?
So what does it show you?
Follow us on Twitter @IHSEViews
-
- Posts: 12
- Joined: Mon Jan 29, 2018 9:57 am
Re: How to run a time series model on panel data?
I open my ~30 company data. I run the program. I open one of the calculated equations and I get this:
Dependent Variable: Y15580
Method: Least Squares
Date: 02/01/18 Time: 09:13
Sample: 1 957 IF GVKEY=GVK
Included observations: 32
Variable Coefficient Std. Error t-Statistic Prob.
C 0.926976 0.496468 1.867140 0.0717
Y15580(-1) 0.891622 0.063182 14.11191 0.0000
R-squared 0.869079 Mean dependent var 7.891060
Adjusted R-squared 0.864715 S.D. dependent var 0.835122
S.E. of regression 0.307167 Akaike info criterion 0.537612
Sum squared resid 2.830550 Schwarz criterion 0.629221
Log likelihood -6.601793 Hannan-Quinn criter. 0.567978
F-statistic 199.1460 Durbin-Watson stat 2.555694
Prob(F-statistic) 0.000000
Everything is fine. But if for that equation I click on the Resids tab, I get an image of an empty graph with no line for residual, actual or fitted, just empty... as if there are no results. Additionally, if I go to View->Actual, Fitted, Residual -> Actual, Fitted, Residual Table, it is also empty except that it says that the number of Obs is 956. That is wrong. It should be the same number as in the statistics: 32! 956 is the maximum number of Obs. Its as if he is giving me the output for just one company but then if I want to look at the residual stats then he just ran the whole thing without looking at the code and just did the ls for all of the companies at once (which also shouldn't even make sense how he could do that, and even if he did do that then it should show the residuals for all of the companies, as it always does if I just run the ls on all of them without the code).
Mihailo.
Dependent Variable: Y15580
Method: Least Squares
Date: 02/01/18 Time: 09:13
Sample: 1 957 IF GVKEY=GVK
Included observations: 32
Variable Coefficient Std. Error t-Statistic Prob.
C 0.926976 0.496468 1.867140 0.0717
Y15580(-1) 0.891622 0.063182 14.11191 0.0000
R-squared 0.869079 Mean dependent var 7.891060
Adjusted R-squared 0.864715 S.D. dependent var 0.835122
S.E. of regression 0.307167 Akaike info criterion 0.537612
Sum squared resid 2.830550 Schwarz criterion 0.629221
Log likelihood -6.601793 Hannan-Quinn criter. 0.567978
F-statistic 199.1460 Durbin-Watson stat 2.555694
Prob(F-statistic) 0.000000
Everything is fine. But if for that equation I click on the Resids tab, I get an image of an empty graph with no line for residual, actual or fitted, just empty... as if there are no results. Additionally, if I go to View->Actual, Fitted, Residual -> Actual, Fitted, Residual Table, it is also empty except that it says that the number of Obs is 956. That is wrong. It should be the same number as in the statistics: 32! 956 is the maximum number of Obs. Its as if he is giving me the output for just one company but then if I want to look at the residual stats then he just ran the whole thing without looking at the code and just did the ls for all of the companies at once (which also shouldn't even make sense how he could do that, and even if he did do that then it should show the residuals for all of the companies, as it always does if I just run the ls on all of them without the code).
Mihailo.
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13317
- Joined: Tue Sep 16, 2008 5:38 pm
Re: How to run a time series model on panel data?
We'll need to see the workfile/equation. Could you provide it?
Follow us on Twitter @IHSEViews
-
- Posts: 12
- Joined: Mon Jan 29, 2018 9:57 am
Re: How to run a time series model on panel data?
Hello,
I have attached the work file. If you open any eq you will see that the stats are there but the residuals aren't.
Also, I am currently trying to save those equations in a matrix but other then the rbar2 nothing else is saving:
matrix ((@rows(gvkey))/38,9) eq1_m
matrix ((@rows(gvkey))/38,2) ys_adf
scalar rows=@rows(gvkey)
scalar i=1
scalar j=1
while i<rows
scalar gvk=gvkey(i)
smpl if gvkey=gvk
series y{gvk}=log(adjusted_oibdp)
series x{gvk}=log(capital_expenditures)
series s{gvk}=sale
series u{gvk}=cur
equation eq{gvk}.ls y{gvk} c y{gvk}(-1)
eq1_m(j,1) = gvk
eq1_m(j,2) = eq{gvk}.@rbar2
eq1_m(j,3) = eq(gvk}.@coefs(1)
eq1_m(j,4) = eq(gvk}.@tstats(1)
eq1_m(j,5) = eq(gvk}.@coefs(2)
eq1_m(j,6) = eq(gvk}.@tstats(2)
eq1_m(j,7) = eq(gvk}.@coefs(3)
eq1_m(j,8) = eq(gvk}.@tstats(3)
eq1_m(j,9) = eq(gvk}.@se
equation eq{gvk}x.ls y{gvk} c y{gvk}(-1) x{gvk}
equation eq{gvk}tr.ls y{gvk} c y{gvk}(-1) x{gvk} @trend
equation eq{gvk}cur.ls y{gvk} c s{gvk} u{gvk}
eq{gvk}cur.makeresid rescur
freeze(adftable) y{gvk}.uroot(adf)
ys_adf(j,1)= gvk
ys_adf(j,2)= @val(adftable(7,4))
d adftable
while i<rows and gvk=gvkey(i)
i=i+1
wend
j=j+1
wend
Mihailo.
I have attached the work file. If you open any eq you will see that the stats are there but the residuals aren't.
Also, I am currently trying to save those equations in a matrix but other then the rbar2 nothing else is saving:
matrix ((@rows(gvkey))/38,9) eq1_m
matrix ((@rows(gvkey))/38,2) ys_adf
scalar rows=@rows(gvkey)
scalar i=1
scalar j=1
while i<rows
scalar gvk=gvkey(i)
smpl if gvkey=gvk
series y{gvk}=log(adjusted_oibdp)
series x{gvk}=log(capital_expenditures)
series s{gvk}=sale
series u{gvk}=cur
equation eq{gvk}.ls y{gvk} c y{gvk}(-1)
eq1_m(j,1) = gvk
eq1_m(j,2) = eq{gvk}.@rbar2
eq1_m(j,3) = eq(gvk}.@coefs(1)
eq1_m(j,4) = eq(gvk}.@tstats(1)
eq1_m(j,5) = eq(gvk}.@coefs(2)
eq1_m(j,6) = eq(gvk}.@tstats(2)
eq1_m(j,7) = eq(gvk}.@coefs(3)
eq1_m(j,8) = eq(gvk}.@tstats(3)
eq1_m(j,9) = eq(gvk}.@se
equation eq{gvk}x.ls y{gvk} c y{gvk}(-1) x{gvk}
equation eq{gvk}tr.ls y{gvk} c y{gvk}(-1) x{gvk} @trend
equation eq{gvk}cur.ls y{gvk} c s{gvk} u{gvk}
eq{gvk}cur.makeresid rescur
freeze(adftable) y{gvk}.uroot(adf)
ys_adf(j,1)= gvk
ys_adf(j,2)= @val(adftable(7,4))
d adftable
while i<rows and gvk=gvkey(i)
i=i+1
wend
j=j+1
wend
Mihailo.
- Attachments
-
- usadata2.0.wf1
- (3.28 MiB) Downloaded 344 times
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13317
- Joined: Tue Sep 16, 2008 5:38 pm
Re: How to run a time series model on panel data?
Couple of bugs in the program.
First, rather than using:
use
then reference !gvk rather than gvk.
Second lines like:
have a "(" rather than "{"
First, rather than using:
Code: Select all
scalar gvk = gvkey(i)
use
Code: Select all
!gvk = gvkey(i)
then reference !gvk rather than gvk.
Second lines like:
Code: Select all
eq1_m(j,3) = eq(gvk}.@coefs(1)
have a "(" rather than "{"
Follow us on Twitter @IHSEViews
Who is online
Users browsing this forum: No registered users and 37 guests