I've, what I think, the same kind of question. I need to calculate the standard deviation of one-year cash ETR over the time period t-4 to t. One year Cash ETR is defined as cash taxes paid (TXPD) divided by pretax income (PI) less special items (SPI), which is PI_SPI. I've tried the commands above;
but this gives back for every GVKEY the same number, not for every year (date). Below is how my varlist looks like. Hope someone can help me in the right direction.
*edit: forgot to include ETR
*edit2: Think I got the solution...
edit3: edit2 was not the solution, I think this was;
*edit4 (hopefully the last, and sorry for flooding it with edits haha): the previous edit, edit3, was the sd over a 2 year period(?), but I needed it over 5-years ; t-4 to t. So I tried this, and at first glance looks good.
Code:
bysort GVKEY (date): egen SD=sd(TXR)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long GVKEY float(date TXPD PI_SPI ETR) 1004 15856 3.46 14.13 .24486907 1004 16222 4.2 10.39 .4042348 1004 16587 4.791 10.414 .4600538 1004 16952 6.094 59.803 .10190124 1004 17317 8.042 146.591 .05486012 1004 17683 19.454 262.884 .07400222 1004 18048 48.56 381.958 .1271344 1004 18413 78.709 450.448 .17473494 1004 18778 88.521 560.487 .15793587 1004 19144 99.939 667.86 .14964065 1004 19509 124.039 771.16 .1608473 1004 19874 141.339 876.46 .1612612 1004 20239 246.939 889.74 .27754062 1004 20605 282.639 949.44 .2976902 1004 21335 299.639 1026.64 .29186374 1013 16009 0 8.38 0 1013 16375 1.2 50.38 .023818975 1013 16740 10.2 153.28 .06654488 1013 17105 15.6 232.18 .067189254 1013 17470 28.5 347.945 .0819095 end format %tdMon_DD,_CCYY date
*edit2: Think I got the solution...
Code:
egen SD=sd(ETR), by(date) bysort GVKEY (date) : generate SD_0= sum(SD) by GVKEY: generate SD_5 = SD-SD[_n-5]
Code:
bysort GVKEY (date): generate ETR = TXPD/PI_SPI egen SD=sd(ETR), by(date)
Code:
by GVKEY: generate ETR_5 = ETR-ETR[_n-5] egen SD_5=sd(ETR_5), by(date)
Comment