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]

st: RE: RE: TSCS: Subtracting values


From   "DeMichele, Matthew" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: TSCS: Subtracting values
Date   Mon, 18 Nov 2013 11:48:46 -0500

Thanks Joe. That worked. Matthew 

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Joe Canner
Sent: Monday, November 18, 2013 11:32 AM
To: [email protected]
Subject: st: RE: TSCS: Subtracting values

Matthew,

How about:

bysort stateid (year):  gen diff=totbeg-totend[_n-1]

Regards,
Joe Canner
Johns Hopkins University School of Medicine

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of DeMichele, Matthew
Sent: Monday, November 18, 2013 11:19 AM
To: [email protected]
Subject: st: TSCS: Subtracting values

Dear Stata list:

I have a pooled dataset arranged by state and year. I am trying to generate a variable from two existing variables, but I am having trouble figuring out what to tell Stata.
 
Here is a snapshot of what the data look like. I want to generate a variable identifying the difference for each state between the end of year population (totend) and the beginning (totbeg) of the next year's population. For instance, the difference in the totend in 2005 and totbeg 2006 for state 1 and state 2. In the case of state 1, this would be difference 54369-55175 = -806. These are populations for = December
31 and January 1 in which the total should be pretty close. But, I need to do this for all 50 states over 30 years. Any suggestions?

stateid   year       totbeg   totend

1             2005      53865    55175

1             2006      54369    55806

1             2007      55018    53230

1             2008      52187    50418

2             2005      3841      4115

2             2006      4115      4477

2             2007      4477      4596

2             2008      4596      4662

Matthew 


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