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]
Re: st: RE: RE: generating a variable?
From
Ignacio Martinez <[email protected]>
To
[email protected]
Subject
Re: st: RE: RE: generating a variable?
Date
Thu, 28 Jul 2011 17:40:41 -0400
Thanks Sarah
On Thu, Jul 28, 2011 at 4:41 PM, Sarah Edgington <[email protected]> wrote:
> .
> Your example code, in addition to being nonsense in terms of syntax, also
> uses illegal variable names. Moreover, the name and number of variables
> differs from what you describe having in the data. My suggested solution
> ignores your example code and is based solely on your description of the
> data. If your description doesn't accurately reflect what you're working
> with then my suggestion may not help much.
>
> Here's one way to get the four year total:
>
> gen
> total_4_year=(E01==3)+(E02==3)+(E03==3)+(E04==3)+(E05==3)+(E06==3)+(E07==3)+
> (E08==3)+(E09==3)+(E10==3)+(E11==3)+(E12==3)
>
>
> -Sarah
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Nick Cox
> Sent: Thursday, July 28, 2011 12:24 PM
> To: '[email protected]'
> Subject: st: RE: generating a variable?
>
> I am very surprised that you imply that this even works at all. "then" is
> just fantasy code so far as Stata is concerned. Alternatively, if this is a
> mix of Stata and pseudocode, then please show us the real Stata code.
>
> See also
>
> FAQ . . . . . . . . . . . . . . . . . . . . . if command vs. if
> qualifier
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . J.
> Wernow
> 6/00 I have an if or while command in my program that
> only seems to evaluate the first observation,
> what's going on?
> http://www.stata.com/support/faqs/lang/ifqualifier.html
>
> to learn that -if- as you (intend to) use it is not what you want.
>
> Nick
> [email protected]
>
> Ignacio, Martinez
>
> I'm having troubles generating 2 new variables with my data.
>
> I have the following variables: ID; E01-E12 where E01 =3 indicates that i is
> enrolled in a 4 year college in January, and E05=2 means that he is enrolled
> in a 2 year college in may.
>
> I want to generate a 2 new variables Total_2_year that is the total number
> of month that i is enrolled in a 2 year college and total_4_year that is the
> total number of month that i is enrolled in a
> 4 year college.
>
> What is the best way of doing this?
>
> My first attempt was this
> <code>
> *Generates vectors of total months enrolled in college gen total_2_year = 0
> gen total_4_year = 0 gen total_none = 0
>
>
> forvalues month=1/9 {
> if 511200`month'==3 then total_4_year==total_4_year+1
> if 511200`month'==2 then total_2_year==total_2_year+1
> if 511200`month'==1 then total_none==total_none+1
> if 511200`month'==-4 then total_none==-4
> if 511200`month'==-4 then total_2_year==-4
> if 511200`month'==-4 then total_4_year==-4
>
> }
>
> </code>
>
> but i get only zeros... :_(
>
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/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/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/statalist/faq
* http://www.ats.ucla.edu/stat/stata/