Hi
How to create daily value-weighted and equal-weighted averages of earnings ratio X over a window t-1 to t+1 relative to day t?
For daily equal-weighted average calculated at date t
For daily value-weighted average calculated at date t
The above codes calculate the averages for one day, date t, and I want to do so for all observations in a window spanning the period t-1 to t+1 (three days). I have several firm observations each day.
An example of the data is below:
Thanks
How to create daily value-weighted and equal-weighted averages of earnings ratio X over a window t-1 to t+1 relative to day t?
For daily equal-weighted average calculated at date t
Code:
bys date : egen ew_X= mean (X)
Code:
bys date : egen vw_X= wtmean (X), weight(market_value)
The above codes calculate the averages for one day, date t, and I want to do so for all observations in a window spanning the period t-1 to t+1 (three days). I have several firm observations each day.
An example of the data is below:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double(date day) long lpermno double X 4386 4 48063 -.017680526788815442 4387 5 32328 .004979764504273257 4387 5 26710 .013923698163334514 4387 5 45356 .030431487452540987 4388 6 33312 .004819280099424343 4388 6 37487 .061908231434809856 4392 10 41734 -.0047108946665263395 4392 10 30680 .012353034519365353 4392 10 39386 .007323568661099492 4393 11 21733 .0010962955461855245 4393 11 42593 .008016466404701529 4393 11 46754 .014612875383848886 4394 12 31878 .047724595825440544 4394 12 39263 .007307486919867627 4394 12 42462 -.013253157401120177 4395 13 47837 .018265066255042116 4395 13 41996 .0005258543830600333 4395 13 36775 .008686566347012507 4395 13 19940 .0010242368276101013 4396 14 21282 .012426076086511086 4396 14 37073 .2394106870472846 4399 17 46156 -.00840515136005388 4399 17 30234 -.0006765900768512746 4399 17 21397 -.00675601830814635 4399 17 42104 .03558888911356758 4399 17 45022 .0013793108362174368 4399 17 49517 -.02818880793687696 4399 17 28353 .005380657688987578 4399 17 41486 -.02101226676147718 4399 17 41523 -.012747568621689085 4400 18 10487 -.006458697029810499 end format %td date

Comment