Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: loop over regressions per year and calculate variables


From   Léon Bueckins <l.bueckins@zeppelin-university.net>
To   statalist@hsphsun2.harvard.edu
Subject   st: loop over regressions per year and calculate variables
Date   Fri, 3 Dec 2010 18:16:38 +0100

Hi,

I'm having some trouble in calculating variables that are based on the coefficients from my regression, since I use the -by:- option. So my goal is to generate new variables that store the calculation of each regression.

My basic setup is as follow:

* get the year information from my date variable
gen year=year(date)

* regression should be ran for each year
sort year
by year: xtscc ln_csad return_ma absreturn_ma return2_ma

* Calculate Standardized Betas (for each year), since this option is not available for -xtscc- regression
gen b_return_ma = _b[return_ma]
gen b_absreturn_ma = _b[absreturn_ma]
gen b_return2_ma = _b[return2_ma]

egen sd_return_ma = sd(return_ma)
egen sd_absreturn_ma = sd(absreturn_ma)
egen sd_return2_ma = sd(return2_ma)
egen sd_ln_csad = sd(ln_csad)

gen Z_return = b_return_ma * (sd_return_ma/sd_ln_csad)
gen Z_absreturn = b_absreturn_ma * (sd_absreturn_ma/sd_ln_csad)
gen Z_return2 = b_return2_ma * (sd_return2_ma/sd_ln_csad)

* Calculate the variable that I actually need (should have one value per year)
gen phi = abs(Z_return2/Z_absreturn)

***************

I tried to change this setup into a foreach loop but could not get it to work properly, can somebody help me out?

***************

foreach x of varlist year {
display `x'

* How can I now run the regression per year?
xtscc ln_csad return_ma absreturn_ma return2_ma

* And how to calculate the former variables and store them?

}


Help is greatly appreciated!

Regards,

Leon Bueckins






*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index