Statalist


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

Re: st: Re: using vector notation to simplify coding


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: using vector notation to simplify coding
Date   Wed, 12 Aug 2009 13:50:12 +0000 (GMT)

-----------------------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


--- On Wed, 12/8/09, Dan Waldo wrote:

> I suppose that I could write
> 
> .replace ing_1=ing_1/def_7 if mes_1==7
> .replace ing_1=ing_1/def_8 if mes_1==8
> .replace ing_1=ing_1/def_9 if mes_1==9
> .replace ing_1=ing_1/def_10 if mes_1==10
> .replace ing_2=ing_2/def_6 if mes_1==6
> .replace ing_2=ing_2/def_7 if mes_1==7
> .replace ing_2=ing_2/def_8 if mes_1==8
> .replace ing_2=ing_2/def_9 if mes_1==9
> etc
> 
> but this seems so bulky and inelegant -- and this is where
> I thought a vector notation would help ... 

what about:

forvalues t=1/10 {
    forvalues i = 1/2 {
        replace in_`i' = ing_`i' / def_`t' if mes_1 == `t'
    }
}

hope this helps,
Maarten


      

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



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index