Dear Statalist,
I have a panel dataset where stocks are uniquely identified by their permco. For each month, stocks generate returns.
In order to obtain the 3-month returns of each stock I use the following code
where permdiff3 = permno3 - permno. And permno3 = permno[_n-3].
Now I want to calculate the 3-month by excluding all observations in January. I created a dummy-variable called January (= 1)
However, this code doesn't give a "return3m" of zero in October, November and December. While this is something that the code should produce right?
As reference point; the row 36508 represent a observation in January
Thanks in advance,
Huib
I have a panel dataset where stocks are uniquely identified by their permco. For each month, stocks generate returns.
In order to obtain the 3-month returns of each stock I use the following code
Code:
gen return3m = . local N = _N forvalues i = 1/`N' { if permdiff3[`i'] == 0 { qui replace return3m = return[_n+3] in `i' } else { qui replace return3m = 0 in `i' } }
Now I want to calculate the 3-month by excluding all observations in January. I created a dummy-variable called January (= 1)
Code:
gen return3m_eJ = . local N = _N forvalues i = 1/`N' { if permdiff3[`i'] == 0 & January[`i'] ~= 1 { qui replace return3m_eJ = return[_n+3] in `i' } else { qui replace return3m_eJ = 0 in `i' } }
As reference point; the row 36508 represent a observation in January
Thanks in advance,
Huib
Comment