Bookmark and Share

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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: standard deviation around an event


From   "Khieu, Hinh" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: standard deviation around an event
Date   Wed, 31 Jul 2013 12:41:13 +0000

Nick,

Oops, sorry about the attachment.

Here are my codes. Note my sub total calculation code is for the whole dataset and may not be applied to the small sample you have got since I require each firm have at least 9 consecutive years for the standard deviation calculation.
egen numgvkey=group(gvkey)
tsset numgvkey fyear
tsspell numgvkey
bysort numgvkey: egen subtotseq=sum(_seq)
drop if subtotseq<45
gen sdebit = .
forval i = 1/`=_N' {
            if shareissue[`i'] == 1 {
             su ebit if numgvkey==numgvkey[`i'] & _n != `i' & inrange(fyear, fyear[`i'] -4, fyear[`i'] + 4)
             replace sdebit = r(sdebit) in `i'
          }
}

Thank you so much.

Regards,
Hinh

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Wednesday, July 31, 2013 7:24 AM
To: [email protected]
Subject: Re: st: standard deviation around an event

When I post I did not mean send an attachment, as attachments are not allowed on Statalist.

The FAQ, which all members are asked to read before posting, does explain this.

I am amazed that it got through, but it will mess up the digest for many readers.

Since it did get through I will take a look if and when you post

1. The exact (Stata) code you used.

as requested.

Nick
[email protected]


On 31 July 2013 13:15, Khieu, Hinh <[email protected]> wrote:
> 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.
>
> I really appreciate your help.
>
> Regards,
> Hinh
>
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Nick Cox
> Sent: Wednesday, July 31, 2013 6:40 AM
> To: [email protected]
> 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
> [email protected]
>
>
> On 31 July 2013 12:04, Khieu, Hinh <[email protected]> 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.
>>
>> Many thanks in advance.
>>
>> Best,
>> Hinh
>> ________________________________________
>> From: [email protected]
>> [[email protected]] on behalf of Nick Cox 
>> [[email protected]]
>> Sent: Tuesday, July 30, 2013 7:05 AM
>> To: [email protected]
>> 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
>> [email protected]
>>
>>
>> On 30 July 2013 12:29, Nick Cox <[email protected]> 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'
>>>           }
>>> }
>>>
>>> See also
>>>
>>> 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
>>> [email protected]
>>>
>>>
>>> On 30 July 2013 12:09, Khieu, Hinh <[email protected]> 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/

*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index