Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Locating Point Fitting Criteria in Panel Data


From   smerryman@kc.rr.com
To   statalist@hsphsun2.harvard.edu
Subject   st: RE: Locating Point Fitting Criteria in Panel Data
Date   Tue, 01 Mar 2005 06:59:59 -0600

Jason,

My previous answer was wrong.  I missed your the "first year of the 
first three year period" condition.

Try this:
                                       
egen id = group(seller product)
tsset id year
tsspell value, cond(value>0)
egen count = count(_spell) if _spell > 0 , by(id _spell)
gen byte begin = . 
levels id, local(levels)
foreach l of local levels {
    replace begin = cond(_seq == 1, /// 
    cond(_seq[_n+1] > _seq , 1, . ///
    ) , .) if id == `l' & count == 3
}
drop _* count

For example:

  +---------------------------------+
  | seller   product   year   value |
  |---------------------------------|
  |     13       456   1988       0 |
  |     13       456   1989       0 |
  |     13       456   1990       9 |
  |     13       456   1991       0 |
  |     13       456   1992       2 |
  |---------------------------------|
  |     13       456   1993       6 |
  |     13       456   1994       7 |
  |     14         1   1988       1 |
  |     14         1   1989       2 |
  |     14         1   1990       3 |
  |---------------------------------|
  |     14         2   1991       4 |
  |     14         2   1992       5 |
  |     14         2   1993       0 |
  |     14         2   1994       0 |
  |     15         1   1989       0 |
  |---------------------------------|
  |     15         1   1990       1 |
  |     15         1   1991       2 |
  |     15         1   1992       3 |
  +---------------------------------+

. do "C:\DOCUME~1\SCOTT~1.MER\LOCALS~1\Temp\STD07000000.tmp"


  +----------------------------------------------+
  | seller   product   year   value   id   begin |
  |----------------------------------------------|
  |     13       456   1988       0    1       . |
  |     13       456   1989       0    1       . |
  |     13       456   1990       9    1       . |
  |     13       456   1991       0    1       . |
  |     13       456   1992       2    1       1 |
  |     13       456   1993       6    1       . |
  |     13       456   1994       7    1       . |
  |----------------------------------------------|
  |     14         1   1988       1    2       1 |
  |     14         1   1989       2    2       . |
  |     14         1   1990       3    2       . |
  |----------------------------------------------|
  |     14         2   1991       4    3       . |
  |     14         2   1992       5    3       . |
  |     14         2   1993       0    3       . |
  |     14         2   1994       0    3       . |
  |----------------------------------------------|
  |     15         1   1989       0    4       . |
  |     15         1   1990       1    4       1 |
  |     15         1   1991       2    4       . |
  |     15         1   1992       3    4       . |
  +----------------------------------------------+

Hope this helps,
Scott


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index