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]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: Treating similar events in adjacent years in panel set as one |

Date |
Thu, 12 Dec 2013 15:11:57 +0000 |

Various terms used here would refer to runs or spells of identical values. Here I would normally refer you to -tsspell- from SSC. However, I do infer that you can read SJ-7-2 dm0029 . . . . . . . . . . . . . . Speaking Stata: Identifying spells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox Q2/07 SJ 7(2):249--265 (no commands) shows how to handle spells with complete control over spell specification http://www.stata-journal.com/sjpdf.html?articlenum=dm0029 which leads to suggestions like bysort Id (year) : gen spell = X == 1 & (_n == 1 | X[_n-1] == 0) by Id : replace spell = sum(spell) if X == 1 As you have just started Stata, you might like to read up on -by:- in the manuals and/or SJ-2-1 pr0004 . . . . . . . . . . Speaking Stata: How to move step by: step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox Q1/02 SJ 2(1):86--102 (no commands) explains the use of the by varlist : construct to tackle a variety of problems with group structure, ranging from simple calculations for each of several groups to more advanced manipulations that use the built-in _n and _N http://www.stata-journal.com/sjpdf.html?articlenum=pr0004 The code above numbers spells 1, 2, 3 separately for each distinct value of -Id-. If you want spells to be numbered in one sequence within the dataset, use replace spell = sum(spell) if X == 1 without the prefix. Nick njcoxstata@gmail.com On 12 December 2013 13:53, Brinkerink Jasper (OS) <j.brinkerink@maastrichtuniversity.nl> wrote: > Dear Statalist users, > > I just started using Stata. I have browsed through the archives of Statalist, but couldn't find an answer to my question: > > I am working on a panel data set containing investment data for individual companies in various industries over 9 years. I have constructed a dummy variable X that takes value 1 if variable U in a certain year takes a value above a certain threshold α. This variable X denotes the event of interest in my study and will later on be used as the independent variable in my regressions. An example of my panel set thus looks like the following: > > Id year U X(α=1.5) > ----------------------------------- > 1 1 1.4 0 > 1 2 0.8 0 > 1 3 1.7 1 > 1 4 1.1 0 > 1 5 0.7 0 > 1 6 1.8 1 > 1 7 1.3 0 > 1 8 1.2 0 > 1 9 0.9 0 > ----------------------------------- > 2 1 1.1 0 > 2 2 1.2 0 > 2 3 1.8 1 > 2 4 1.9 1 > 2 5 1.3 0 > 2 6 1.4 0 > 2 7 1.6 1 > 2 8 1.2 0 > 2 9 1.4 0 > ----------------------------------- > > In running the regressions I want to classify adjacent events (so two or more consecutive '1' values of X) as one event, rather than multiple events. Consider for example the data above: For company 1, two events took place in the 9 years, in year 3 and in year 6. Company 2 has 3 '1' values for U. However, I want to treat the two 1's in year 3 and 4 as the same unique event, rather than 2 seperate events for theoretical reasons. How could I implement this efficiently in Stata? > > Thanks for any consideration, > > Jasper Brinkerink > > p.s. It might be important to note that I am using Stata 12 in a secured remote access setting, in which I have no control over the software. Furthermore, it is impossible to import external files into this setting, making it impossible to use external macros for example. Therefore, only solutions using internal Stata 12 syntax will be applicable. > * > * 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/

**References**:**st: Treating similar events in adjacent years in panel set as one***From:*"Brinkerink Jasper (OS)" <j.brinkerink@maastrichtuniversity.nl>

- Prev by Date:
**Re: st: margeff after mlogit** - Next by Date:
**Re: st: table command returns different values every time** - Previous by thread:
**st: Treating similar events in adjacent years in panel set as one** - Next by thread:
**Re: Re: st: Treating similar events in adjacent years in panel set as one** - Index(es):