Hi everyone! I have some issues in running two loops.
What I want to do is to estimate alpha and beta coefficients for each id and date in my dataset. what I want to obtain is a different alpha and beta and residuals for each line.
What I implemented is the following code:
However, my loops are not running correctly and I have an estimate only for one alpha and one beta, without any error message.
Do you have any idea of why?
Thanks for your help,
Andrea
What I want to do is to estimate alpha and beta coefficients for each id and date in my dataset. what I want to obtain is a different alpha and beta and residuals for each line.
What I implemented is the following code:
Code:
g alpha=. g beta1=. g residuals=. qui levelsof(date), local(date) foreach date of local date { levelsof id, local(levels) foreach v of local levels { gen date_250 = date-250 if date == `date' gen date_50 = date-50 if date == `date' egen d250 = mean(date_250) egen d50 = mean(date_50) format %tdDD/NN/CCYY date_250 format %tdDD/NN/CCYY date_50 format %tdDD/NN/CCYY d250 format %tdDD/NN/CCYY d50 gen check = (date>=d250 & date<=d50) quietly reg lnstock_return lnmkt_return if id ==`v' & check ==1, r predict temp2 if id== `v', resid replace residuals = temp2 if id == `v' & date == `date' drop temp2 replace alpha = _b[_cons] if id ==`v' & date == `date' replace beta1 = _b[lnmkt_return] if id ==`v' & date == `date' } drop check d50 d250 date_* }
Do you have any idea of why?
Thanks for your help,
Andrea
Comment