Hi, long time reader, first time poster, I'm using Stata 12 on Mac.
My dataset is a panel dataset loaded into Stata, with 14 groups and a weekly time variable for 14 years. The data is grouped via 'id' which takes values from 1-14 and the data is in long format.
I've been experimenting with the loop commands and looking at the manuals, but just cant seem to get the right way for what I want to do. My data is currencies, and I wish to calculate the yearly forward premium i.e. reg y x for each currency (id), which i get to work as:
foreach i of varlist id {
reg y x
}
But this only seems to run one regression, where as i want it to run a separate regression for each id code. If possible, i'd like it to run per currency code and per year (I've defined a year variable already from 2000-2014) - I can do this manually but this would involve (14*14) 196 different regressions which seems slightly inefficient, given that I'm getting closer to correct way, and there should be a loop code to get this to work.
Then (I know this may be detracting from the initial issue), is it possible to take the fitted values for each regression and run another regression, taking the 'x' from these regressions and then running a new regression for each year and currency code, i.e. reg x var1 var2 var3. obviously this would need to be incorporated into the loop for Stata to take the fitted values from the previous regression (I may be incorrect here), but that is ultimately what I am trying to do.
Any help or comments much appreciated - apologies if I've missed anything important on this post, it's my first post.
Thanks!
My dataset is a panel dataset loaded into Stata, with 14 groups and a weekly time variable for 14 years. The data is grouped via 'id' which takes values from 1-14 and the data is in long format.
I've been experimenting with the loop commands and looking at the manuals, but just cant seem to get the right way for what I want to do. My data is currencies, and I wish to calculate the yearly forward premium i.e. reg y x for each currency (id), which i get to work as:
foreach i of varlist id {
reg y x
}
But this only seems to run one regression, where as i want it to run a separate regression for each id code. If possible, i'd like it to run per currency code and per year (I've defined a year variable already from 2000-2014) - I can do this manually but this would involve (14*14) 196 different regressions which seems slightly inefficient, given that I'm getting closer to correct way, and there should be a loop code to get this to work.
Then (I know this may be detracting from the initial issue), is it possible to take the fitted values for each regression and run another regression, taking the 'x' from these regressions and then running a new regression for each year and currency code, i.e. reg x var1 var2 var3. obviously this would need to be incorporated into the loop for Stata to take the fitted values from the previous regression (I may be incorrect here), but that is ultimately what I am trying to do.
Any help or comments much appreciated - apologies if I've missed anything important on this post, it's my first post.
Thanks!

Comment