Hello statalist community,
I am working on my thesis and have encountered the following issue when preparing my dataset:
I have merged daily return data from CRSP with quarterly reporting data from Compustat. The quarterly data was made public on the date indicated by the reporting_date, but the data published in that report obviously corresponds to a date previous to that. Daily return data ranges over many years, for many different stocks. I now need to calculate the standard deviation of the excess returns, in each case for a 45-day period, ending 10 days before the reporting dates. I would like to do this for every reporting_date for every permno. Please see an example of my data below:
input double permno long(date reporting_date) float excess_return
10010 10156 . -.02708268
10010 10157 . .005845358
10010 10160 . -.02454966
10010 10161 . -.05564585
10010 10162 . -.03952751
10010 10163 . -.002447468
10010 10164 . .0455881
10010 10165 10245 .
10010 10167 . .06420771
10010 10168 . -.15954015
10010 10169 . .13668042
10010 10170 . .01815607
10010 10171 . .01033406
10010 10174 . -.04951261
10010 10175 . .13724907
10010 10176 . -.08172845
10010 10177 . .05281845
10010 10178 . .04306433
10010 10181 . -.002760191
10010 10182 . -.02001336
10010 10183 . -.008839875
10010 10184 . .01964553
10010 10185 . -.07655262
10010 10188 . -.15768693
10010 10189 . -.01353516
10010 10190 . .005196954
10010 10192 . .056017
10010 10195 . .16974324
10010 10196 . -.005207345
10010 10197 . .1496127
10010 10198 . -.07011753
10010 10199 . .08459848
10010 10202 . -.01641954
10010 10203 . -.05716385
10010 10204 . .05511259
10010 10205 . -.017439324
10010 10206 . .02835849
10010 10209 . -.05973966
10010 10210 . -.003885546
10010 10211 . -.01931514
10010 10212 . .08233552
10010 10213 . .010260553
10010 10216 . -.003440613
10010 10217 . .0003619183
10010 10218 . -.04361133
10010 10219 . .065786
10010 10223 . -.05249239
10010 10224 . .02006706
10010 10225 . -.01194168
10010 10226 . .06602075
10010 10230 . -.06364613
10010 10231 . -.04398114
10010 10232 . -.03553922
10010 10233 . .02590137
10010 10234 . .10373606
10010 10237 . -.02420747
10010 10238 . -.02279297
10010 10239 . -.002029145
10010 10240 . .015212037
10010 10241 . -.03876884
10010 10244 . -.0003627767
end
format %td date
format %td reporting_date
I have tried various code in an attempt to generate my return volatility variable RETVOL, for example:
Thank you in advance,
Benedikt
I am working on my thesis and have encountered the following issue when preparing my dataset:
I have merged daily return data from CRSP with quarterly reporting data from Compustat. The quarterly data was made public on the date indicated by the reporting_date, but the data published in that report obviously corresponds to a date previous to that. Daily return data ranges over many years, for many different stocks. I now need to calculate the standard deviation of the excess returns, in each case for a 45-day period, ending 10 days before the reporting dates. I would like to do this for every reporting_date for every permno. Please see an example of my data below:
input double permno long(date reporting_date) float excess_return
10010 10156 . -.02708268
10010 10157 . .005845358
10010 10160 . -.02454966
10010 10161 . -.05564585
10010 10162 . -.03952751
10010 10163 . -.002447468
10010 10164 . .0455881
10010 10165 10245 .
10010 10167 . .06420771
10010 10168 . -.15954015
10010 10169 . .13668042
10010 10170 . .01815607
10010 10171 . .01033406
10010 10174 . -.04951261
10010 10175 . .13724907
10010 10176 . -.08172845
10010 10177 . .05281845
10010 10178 . .04306433
10010 10181 . -.002760191
10010 10182 . -.02001336
10010 10183 . -.008839875
10010 10184 . .01964553
10010 10185 . -.07655262
10010 10188 . -.15768693
10010 10189 . -.01353516
10010 10190 . .005196954
10010 10192 . .056017
10010 10195 . .16974324
10010 10196 . -.005207345
10010 10197 . .1496127
10010 10198 . -.07011753
10010 10199 . .08459848
10010 10202 . -.01641954
10010 10203 . -.05716385
10010 10204 . .05511259
10010 10205 . -.017439324
10010 10206 . .02835849
10010 10209 . -.05973966
10010 10210 . -.003885546
10010 10211 . -.01931514
10010 10212 . .08233552
10010 10213 . .010260553
10010 10216 . -.003440613
10010 10217 . .0003619183
10010 10218 . -.04361133
10010 10219 . .065786
10010 10223 . -.05249239
10010 10224 . .02006706
10010 10225 . -.01194168
10010 10226 . .06602075
10010 10230 . -.06364613
10010 10231 . -.04398114
10010 10232 . -.03553922
10010 10233 . .02590137
10010 10234 . .10373606
10010 10237 . -.02420747
10010 10238 . -.02279297
10010 10239 . -.002029145
10010 10240 . .015212037
10010 10241 . -.03876884
10010 10244 . -.0003627767
end
format %td date
format %td reporting_date
I have tried various code in an attempt to generate my return volatility variable RETVOL, for example:
egen RETVOL = std(excess_return) if date >= (reporting_date - 55) & date < (reporting_date - 10), by(permno reporting_date)However, I can't seem to get it to work. Would love some help.
Thank you in advance,
Benedikt
Comment