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 <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: standard deviation around an event
Date   Wed, 31 Jul 2013 12:39:45 +0100

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/


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