Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Ignacio Martinez <ignacio@virginia.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: generating a variable? |

Date |
Thu, 28 Jul 2011 18:08:10 -0400 |

Thanks a lot for the help. I have my code doing what i need now :-) http://goo.gl/Ul5YO Thanks again! -Ignacio On Thu, Jul 28, 2011 at 6:00 PM, Sarah Edgington <sedging@ucla.edu> wrote: > . > Your code isn't producing errors as written, but it also isn't doing > anything like what you intend. > Stata is reading the first iteration of the first line as: > if 5112001==3 then total_4_year==total_4_year+1 > Because variable names can't start with numbers Stata is evaluating whether > 5112001==3. Since the number 5112001 is not equal to the number 3 Stata > doesn't even process the rest of the line. Thus you don't get an error > message telling you that the rest of the line doesn't make sense. On the > other hand, if you were to say "if 3==3 then x=1" you would get the error > "unrecognized command: then." > So the reason you're getting all zeros is that you set the values of your > totals to zero before the loop. Stata isn't actually doing anything to your > data in the loop because none of the if statements evaluate as true. If you > were to correct your code so that it used the actual variable name E5112001 > you would get errors. > > -Sarah > > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ignacio Martinez > Sent: Thursday, July 28, 2011 2:39 PM > To: statalist@hsphsun2.harvard.edu > Subject: Re: st: RE: generating a variable? > > Hi Nick, > > My code runs but does not work (i only get a vector of zeros). > http://goo.gl/27nG6 > > Any idea what is the right way of doing what i want? > > Thanks! > > -Ignacio > > On Thu, Jul 28, 2011 at 3:23 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote: >> 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 >> n.j.cox@durham.ac.uk >> >> 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/ > * * 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/

**References**:**st: generating a variable?***From:*Ignacio Martinez <ignacio@virginia.edu>

**st: RE: generating a variable?***From:*Nick Cox <n.j.cox@durham.ac.uk>

**Re: st: RE: generating a variable?***From:*Ignacio Martinez <ignacio@virginia.edu>

**RE: st: RE: generating a variable?***From:*"Sarah Edgington" <sedging@ucla.edu>

- Prev by Date:
**RE: st: RE: generating a variable?** - Next by Date:
**st: How to log copy/paste in data editor (Stata 11)** - Previous by thread:
**RE: st: RE: generating a variable?** - Next by thread:
**st: tutorial for -outreg-** - Index(es):