Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Rebecca Pope <rebecca.a.pope@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: efficient way to use local |
Date | Mon, 25 Feb 2013 12:14:41 -0600 |
I'm not sure this is "efficient", but you would need to use two -forvalues- & you must close both sets of `'. Also, you must have == instead of = since you are asking Stata for a logical test. forvalues i=1/2 { forvalues j=1/2 { regress il`i't `X`i'' if mon==`j' } } (Code not tested) This will run the regression il1t X1 for mon==1 and mon==2 and then switch to il2t and X2. Rebecca On Mon, Feb 25, 2013 at 12:03 PM, Rodrigo Briceño <rjbriceno@gmail.com> wrote: > Dear Stata users. I am dealing with a dataset that has two slightly > sets of explanatory and dependent variables. The sets are defined by > having a 1 or 2 number inside their names and also a 1 or 2 number > inside the values of one of the variables. My dependents are il1t and > il2t. The values on the variable mon are 1 and 2. So in total my > output is composed by 4 regressions (one for each 1 and 2t, and one > for each mon value). > > I tried to do the following: > > local X1 "mc pmv1t dr1 dr2 dpl1t" > local X2 "mc pmv2t dr1 dr2 dpl2t" > > forvalues i= 1 2{ > > regress il`i't `X`i' if mon=`i' > } > > but I got the error: invalid syntax r(198). I am not sure if you can > use a local inside a local as I expressed on `X`i' > > > Any help is fully appreciated. > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/