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

Re: st: differencing


From   "Eric G. Wruck" <ewruck@econalytics.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: differencing
Date   Mon, 14 Nov 2005 01:50:09 -0500

You were close but your generate (gen) statement wasn't quite right.


. bysort year state county: gen employdiff = employment - employment[_n - 1]
(2 missing values generated)

. l, noobs

  +---------------------------------------------+
  | year   state   county   employ~    employ~f |
  |---------------------------------------------|
  |    1       1        1         10          . |
  |    1       1        1         15          5 |
  |    2       2        1         20          . |
  |    2       2        1         30         10 |
  +---------------------------------------------+


Eric


>Hi I wasn't able to find anything on the archives adressing this issue.
>
>My data is structured as follows
>
>year    state   county   employment
>1            1         1            10
>2            1         1            20
>1            2         1            15
>2            2         1            30
>...
>for 6 years, 50 states, and some counties in each state. I have 1.5 million observations.
>
>I want to construct a variable that is the difference in employment by year in each state and county.
>
>I tried
>
>by year state county, sort: gen newvar = employment-employment[_n-1]  but that didn't work.
>
>Any suggestions?
>Thank you!



-- 

===================================================

       Eric G. Wruck
       Econalytics
       2535 Sherwood Road
       Columbus, OH  43209

       ph:      614.231.5034
       cell:    614.330.8846
       eFax:    614.573.6639
       eMail:   ewruck@econalytics.com
       website: http://www.econalytics.com

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