Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# RE: st: standard deviation around an event

 From "Khieu, Hinh" To "'statalist@hsphsun2.harvard.edu'" Subject RE: st: standard deviation around an event Date Wed, 31 Jul 2013 12:15:15 +0000

```Nick,

Thanks for your note. The data is attached as a Stata file. I have manually (using Excel) calculated the lag standard deviation of EBIT and forward standard deviation of EBIT for one firm (represented by gvkey). Whenever either shareissue or sharerepurchase is equal to 1, the standard deviation should skip that year in the calculation, which means the standard deviation is that of only two or three observations since I wanted to calculate the standard deviation of the previous four and the following four years around the event. The event in this case is either shareissue or sharerepurchase. There are 3 firms (i.e., 3 gvkey) with different year lengths in the sample dataset.

My goal is to compare the standard deviation of EBIT before and after the event to see if they are statistically different.

Regards,
Hinh

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Wednesday, July 31, 2013 6:40 AM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: standard deviation around an event

You need to post

1. The exact code you used.

2. A small realistic dataset to work with. That could be as small as
20 or so observations. Two firms are needed to test the panel aspect.

Otherwise this is too difficult to answer.
Nick
njcoxstata@gmail.com

On 31 July 2013 12:04, Khieu, Hinh <Hdkhieu@usi.edu> wrote:
> Nick,
>
> Neither code in your responses works. It generates a column named "sd" which contains just dots. I wonder if you could help further. My knowledge about Stata is too limited to debug your program.
>
>
> Best,
> Hinh
> ________________________________________
> From: owner-statalist@hsphsun2.harvard.edu
> [owner-statalist@hsphsun2.harvard.edu] on behalf of Nick Cox
> [njcoxstata@gmail.com]
> Sent: Tuesday, July 30, 2013 7:05 AM
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: standard deviation around an event
>
> The easy and difficult versions of your problem can be cast as one in
> the following way:
>
> 1. A spell of share issues years is one or more years in which each
> year included a share issue.
>
> 2. Each spell defines a first year and a last year. (In the case of a
> spell of length one, these are the same.)
>
> Using -tsspell- from SSC, do something like this
>
> ssc inst tsspell            /// only needed once
>
> tsset firmid year
> tsfill
>
> tsspell, cond(shareissue==1)
> egen firstyear = min(year), by(firmid _spell) egen lastyear =
> max(year), by(firmid _spell)
>
> gen sd = .
>
> forval i = 1/`=_N' {
>             if shareissue[`i'] == 1 {
>              su earnings if firmid==firmid[`i'] & (inrange(year,
> firstyear[`i'] -4, firstyear[`i'] - 1) | inrange(year,
> lastyear[`i']+1, lastyear[`i'] + 4))
>              replace sd = r(sd) in `i'
>           }
> }
>
> There is probably something I got wrong here, but it may help. I don't
> know what you do if the four years before a share issue or after a
> share issue include other share issues.
> Nick
> njcoxstata@gmail.com
>
>
> On 30 July 2013 12:29, Nick Cox <njcoxstata@gmail.com> wrote:
>> There are various ways round this in Stata; I don't know about STATA.
>> This is quick to code and slow to run. Some other methods require
>> more code but would be faster. I tackled your first problem only.
>>
>> gen sd = .
>>
>> forval i = 1/`=_N' {
>>             if shareissue[`i'] == 1 {
>>              su earnings if firmid==firmid[`i'] & _n != `i' &
>> inrange(year, year[`i'] -4, year[`i'] + 4)
>>              replace sd = r(sd) in `i'
>>           }
>> }
>>
>>
>> SJ-7-3  pr0033  . . . . . . . . . . . . . .  Stata tip 51: Events in intervals
>>         . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
>>         Q3/07   SJ 7(3):440--443                                 (no commands)
>>         tip for counting or summarizing irregularly spaced
>>         events in intervals
>>
>> http://www.stata-journal.com/sjpdf.html?articlenum=pr0033
>>
>> Nick
>> njcoxstata@gmail.com
>>
>>
>> On 30 July 2013 12:09, Khieu, Hinh <Hdkhieu@usi.edu> wrote:
>>
>>> I have a panel unbalanced data (firm ID, year, share issue year dummy, earnings). I need to calculate the standard deviation of earnings four years before share issue year and four years after share issue year. (I do not have the precise day and month of share issues; I only have year). I can certainly require my data have at least 9 consecutive observation years. That is, the standard deviation cannot include the year of the share issue. I do not know how to exclude that year from the standard deviation in STATA. Also, another problem is that sometimes firm can issue shares two or three years in a row.  In this case, I need to use only the four years before the first issue and the four years after the last consecutive share issue to calculate the standard deviation of earnings.
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```

Attachment: ebitvol_test.dta
Description: ebitvol_test.dta