Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: creating a new variable?


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: creating a new variable?
Date   Sun, 19 Aug 2007 17:13:06 +0100

This FAQ was also cited in a thread started earlier by 

<http://www.hsph.harvard.edu/cgi-bin/lwgate/STATALIST/archives/statalist.0708/date/article-541.html> 

Hence postings in that thread might be of interest
to people interested in this one. 

Nick 
n.j.cox@durham.ac.uk 

Austin Nichols

> There is a relevant FAQ:
> http://www.stata.com/support/faqs/data/members.html


Marilyn Ibarra 

> > >> I have the following variables: state, born, and total.  
> I would like
> > >> to create two new variables: x and y.
> > >> I would like "X" and "Y" to be the sum of Total for certain
> > >> observations.  Such as this:
> > >> state    birthstate total     "X"          "Y"
> > >> 1         3           6      7+9+6        7+6
> > >> 2         3           7      6+9+6        6+6
> > >> 3         3           9      6+7+6        6+7+6
> > >> 4         3           6      6+7+9        6+7
> > >>
> > >> State is the state they live in now.  Birthstate is the 
> state they
> > >> were born in.  For anyone born in state 2, I want "X" to 
> be the sum of
> > >> Total for the other states they do not live in.  For example, for
> > >> person born in state 2, now living in state 1, I want to 
> sum the Total
> > >> for other people born in state 2 who live in state 1, 
> state 3, and
> > >> state 4.
> > >> To create "Y", for example, for person born in state 2, living in
> > >> state 1, I want to sum Total for other persons born in 
> the same state
> > >> who now live in state 3,and 4.  I don't want to include for this
> > >> person's sum of Total, the combination of state 2 and 
> born in state
> > >> 2.  And the same for born in state 3, living in state 1, 
> I want to
> > >> exclude born in state 3, living in 3, but include in the 
> sum of the
> > >> Total born in state 3, living in state 2 and 4.  For the 
> sum of Total,
> > >> for the  observation, born in state 3 living in state 3, 
> I want to
> > >> include the sum of Total for anyone else living in 
> another state that
> > >> is not state 3, so state 1, 2, and 4 would be included 
> in the sum of
> > >> Total for this observation.

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