Dear Statalist
In my data set , I have firms that are classified into 10 portfolios each year suing the following code:
egen portfolio = xtile(op2WA) , by(yr) p(10(10)90)
This groups firms into 10 portfolios (deciles) each year, based on the ranking variable (op2WA).
Obviously each portfolio will contain a number of firms and those firms have available stock returns , each year.
My first task now is to calculate the portfolio mean return and excess return ( portfolio return minus risk free rate RF) each year, so I can use excess returns later in a time series regression for each portfolio.
I was calculating mean returns and excess returns using a simple code, which I doubt now , might not be correct.
**The simple code
egen portret=mean(ret), by (portfolio yr) // for mean portfolio returns
gen portret_excess= portret-RF // for excess returns
I doubted this code, and now changed it to this code:
**The new code
forvalues i = 1(1)10 {
egen portret`i'm = mean(ret), by (yr) //to calculate portfolio return
}
forvalues i = 1(1)10 {
gen portret`i'e = portret`i'm - RF // to calculate portfolio excess return
}
Now, the problem seems to be in running the time series regression (aim is run an annual time series regression for each portfolio and estimate each portfolio intercept and its t statistics). I tried with the following code:
gen alpha==.
gen alpha_t==.
forvalues i=1/10 {
reg portret`i'e MKT SMB HML MOM // MKT , SMB, HML, MOM are returns on risk factors
replace alpha=_b[_cons] if portfolio==`i'
replace alpha_t= alpha/_se[_cons] if portfolio==`i'
}
The good news is that the code seems to work, but the bad news is that all alpha and alpha_t are the same ? It does not seems to do what I intend to do !!
My questions are:
1- Is the simple code for mean and excess return incorrect? is the new code better ?
2- Can anyone debug the time series code
The following link, chapter 5 , was recommended by a Stata user here in the forum to run a very similar regression....That's why I tried to do something similar, but failed
http://lipas.uwasa.fi/~sjp/Teaching/...ectures/p5.pdf
Best
Ahmed
In my data set , I have firms that are classified into 10 portfolios each year suing the following code:
egen portfolio = xtile(op2WA) , by(yr) p(10(10)90)
This groups firms into 10 portfolios (deciles) each year, based on the ranking variable (op2WA).
Obviously each portfolio will contain a number of firms and those firms have available stock returns , each year.
My first task now is to calculate the portfolio mean return and excess return ( portfolio return minus risk free rate RF) each year, so I can use excess returns later in a time series regression for each portfolio.
I was calculating mean returns and excess returns using a simple code, which I doubt now , might not be correct.
**The simple code
egen portret=mean(ret), by (portfolio yr) // for mean portfolio returns
gen portret_excess= portret-RF // for excess returns
I doubted this code, and now changed it to this code:
**The new code
forvalues i = 1(1)10 {
egen portret`i'm = mean(ret), by (yr) //to calculate portfolio return
}
forvalues i = 1(1)10 {
gen portret`i'e = portret`i'm - RF // to calculate portfolio excess return
}
Now, the problem seems to be in running the time series regression (aim is run an annual time series regression for each portfolio and estimate each portfolio intercept and its t statistics). I tried with the following code:
gen alpha==.
gen alpha_t==.
forvalues i=1/10 {
reg portret`i'e MKT SMB HML MOM // MKT , SMB, HML, MOM are returns on risk factors
replace alpha=_b[_cons] if portfolio==`i'
replace alpha_t= alpha/_se[_cons] if portfolio==`i'
}
The good news is that the code seems to work, but the bad news is that all alpha and alpha_t are the same ? It does not seems to do what I intend to do !!
My questions are:
1- Is the simple code for mean and excess return incorrect? is the new code better ?
2- Can anyone debug the time series code
The following link, chapter 5 , was recommended by a Stata user here in the forum to run a very similar regression....That's why I tried to do something similar, but failed

http://lipas.uwasa.fi/~sjp/Teaching/...ectures/p5.pdf
Best
Ahmed
Comment