Dear all,
I have a dataset containing roughly 200 companies with daily stock data for 10 years.
The variables are: date, companyid, Ri_Rft, B_Ret, SMB, HML
I need to run reg Ri_Rft B_Ret SMB HML for every company in the sample monthly.
After this I need to save the Variance of the Error Term as a new variable.
I have a the following code set up:
However, I have two problems with this setup.
First, I am not sure if the "predict, stdp" command achieves my goal of saving the variance of the error term.
Will the new variable 'resid' contain the variance of the error term?
Second, this code only works if I reduce my sample to roughly half the companies, or else it gives an error: no room to add more variables.
Is this solved simply by using set maxvar and how does this work? Where should I place it in my code?
Kind Regards,
Bram van Vorstenbosch
I have a dataset containing roughly 200 companies with daily stock data for 10 years.
The variables are: date, companyid, Ri_Rft, B_Ret, SMB, HML
I need to run reg Ri_Rft B_Ret SMB HML for every company in the sample monthly.
After this I need to save the Variance of the Error Term as a new variable.
I have a the following code set up:
Code:
gen resid=. levelsof id, local(groups) foreach a of local groups { quietly reg Ri_Rft B_Ret SMB HML if id==`a' tempvar d predict `d', stdp replace resid=`d' if id==`a' }
First, I am not sure if the "predict, stdp" command achieves my goal of saving the variance of the error term.
Will the new variable 'resid' contain the variance of the error term?
Second, this code only works if I reduce my sample to roughly half the companies, or else it gives an error: no room to add more variables.
Is this solved simply by using set maxvar and how does this work? Where should I place it in my code?
Kind Regards,
Bram van Vorstenbosch
Comment