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   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: standard deviation around an event
Date   Wed, 31 Jul 2013 15:38:12 +0100

Thanks for the code you used, which bears only partial resemblance to
what I suggested. That's OK in itself, naturally, but it does make
your previous post -- in effect asking me to detect bugs in code you
had changed but weren't showing me -- rather puzzling.

You broke the code if only by changing

r(sd)

to

r(sdebit)

-summarize- does not leave r(sdebit) in its wake. I wrote r(sd) and
that was what was needed.

Nick
njcoxstata@gmail.com


On 31 July 2013 13:41, Khieu, Hinh <Hdkhieu@usi.edu> wrote:
> 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: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
> Sent: Wednesday, July 31, 2013 7:24 AM
> To: statalist@hsphsun2.harvard.edu
> 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
> njcoxstata@gmail.com
>
>
> On 31 July 2013 13:15, Khieu, Hinh <Hdkhieu@usi.edu> 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: 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.
>>>
>>> Many thanks in advance.
>>>
>>> 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'
>>>>           }
>>>> }
>>>>
>>>> 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
>>>> 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/
>
> *
> *   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