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

Re: st: Generate


From   Ada Ma <pec187@abdn.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Generate
Date   Thu, 24 Feb 2005 13:01:09 +0000

using the -by- or -bysort- might help. since it look like you haven't specified your whole set of conditions in your query I don't think I can simplify all the conditions for you, but you can certainly simplify conditions 1 and 2 with:

bysort nivel sex: gen var2=varold02 if sex==2


GLORIA ZAMBRANO ROZAS wrote:


Hi,
I am new in stata and want to generate several new variables, some of them
under  the same conditionals, something like this:

gen var1= varold01  if  ( nivel=1 & area=1 & sex=1)
gen var2=varold02   if ( nivel=1 & area=1 & sex=2)

gen var3= varold03  if  ( nivel=1 & area=2 & sex=1)
gen var2=varold02   if ( nivel=1 & area=2 & sex=2)

gen var4= varold04  if  ( nivel=1 & area=1 )
gen var5=varold05   if ( nivel=1 & area=2 )

I want to know if stata has a command that let me do something like this:

      if nivel=1 & area=1 then do;

                gen var2=varold02   if (sex=2)
                gen var4= varold04

       if nivel=1 and area=2 then do;

               gen var3= varold03  if  (  sex=1)
               gen var2=varold02   if (  sex=2)
               gen var5=varold05

that let me reduce the number of conditionals


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