[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Shehzad Ali" <sia500@york.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: using different macros everytime |

Date |
Sun, 15 Jun 2008 15:06:40 +0100 |

Thanks, Martin. Let me write down a few details about the analysis I am trying to run. Please ignore if some of the details are irrelevant. I am trying to run what they call 'standardisation' in literature. So here is what I intend to do. First loop: 1. run treatreg model: treatreg y1 x1 x2 x3 x4 x5, treat(y2=x1 x2 x3 x4 x5 instrument1) 2. then set x1 x2 at their mean values (first generate copies of x1 x2, i.e. x1_copy x2_copy, then summarize original x1 x2 and replace them with their mean values). 3.then predict yhat (so basically it uses coefficients from treatreg but x1 x2 are at their mean values and others at their actual values) 4. drop x1 x2 (which were set at their mean values) and then rename x1_copy and x2_copy as x1 x2 (so these variables are back as original) Second loop: 4. Run the same as above but this time setting x2 x4 x5 at their mean values Going on further, I have a few more loops where the variables which are set to their mean values are different (no pattern of selection of variables) What I was thinking of doing was to define sets of macros, i.e. for first loop, define macro1 as variables to be set at their mean value and macro2 as variables to be left as original. For second loop, I do the same and it goes on until I have run all the loops I wanted to run. What I needed help with is how to assign names to each macro and then I can run a foreach loop so that the macros are defined at the start and then treatreg and the rest is run as a loop several times. I would truly appreciate your help with this. With sincere thanks, Shehzad -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Maarten buis Sent: 14 June 2008 22:53 To: statalist@hsphsun2.harvard.edu Subject: RE: st: using different macros everytime It is usually better practice to work with locals. Anyhow the answer to your question depends on the kind of pattern you want those models to follow. Do you want something like x1 x2 x3 x1 x2 x4 x1 x2 x5 or x1 x2 x3 x1 x2 x3 x4 x1 x2 x3 x4 x5 or all combinations. Moreover, do these variables have such systematic names, or do they have more meaningful, but less systematic names? -- Maarten --- Shehzad Ali <sia500@york.ac.uk> wrote: > Sorry, Martin, it was a mistake. I actually meant global. The models > I am > currently using are: > > * First model: > > global xvar "x1 x2" > > global zvar "x1 x2 v1" > > treatreg y1 $xvars, treat(y2=$zvars) > > * Second model: > > global xvar "x2 x3 x4" > > global zvar "x2 x3 x4 v1" > > treatreg y1 $xvars, treat(y2=$zvars) > > Note that I am not just adding one or two additional variables in the > second > model, but I am actually using a different set of variables the > second time. > Now I want to loop this somehow so that I just write the - treatreg - > command line once and - foreach - can pick up different sets of > macros each > time the loop is run. Can you please suggest the best way to do it? > > Thanks, > > Shehzad > > > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Martin > Weiss > Sent: 14 June 2008 15:55 > To: statalist@hsphsun2.harvard.edu > Subject: Re: st: using different macros everytime > > Just a remark: are you sure you want to reference a -local- with the > $ > sign? I do not think that this will actually work... > > Zitat von Shehzad Ali <sia500@york.ac.uk>: > > > Hi, > > > > This is probably a very simple question but just reflects my > > inexperience of using foreach loops. > > > > I want to run a 2 separate treatreg models with the same y var but > > different set of x vars. Here is what I am doing: > > > > * First model: > > > > local xvar "x1 x2" local zvar "x1 x2 v1" > > > > treatreg y1 $xvars, treat(y2=$zvars) > > > > * Second model: > > > > local xvar "x1 x2 x3" local zvar "x1 x2 x3 v1" > > > > treatreg y1 $xvars, treat(y2=$zvars) > > > > Now I want to loop this somehow so that I just write the - treatreg > - > > line once but - foreach - can pick up different sets of macros. Can > you > > suggest the best way to do it? > > > > Thank you, > > > > Shehzad > > * > > * 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/ > > > > > * > * 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/ > > > * > * 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/ > ----------------------------------------- Maarten L. Buis Department of Social Research Methodology Vrije Universiteit Amsterdam Boelelaan 1081 1081 HV Amsterdam The Netherlands visiting address: Buitenveldertselaan 3 (Metropolitan), room Z434 +31 20 5986715 http://home.fsw.vu.nl/m.buis/ ----------------------------------------- __________________________________________________________ Sent from Yahoo! Mail. A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html * * 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/ * * 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/

**Follow-Ups**:**RE: st: using different macros everytime***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**RE: st: using different macros everytime***From:*"Shehzad Ali" <sia500@york.ac.uk>

**RE: st: using different macros everytime***From:*Maarten buis <maartenbuis@yahoo.co.uk>

- Prev by Date:
**Re: st: 64 bit Stata for the Mac /feature request** - Next by Date:
**Re: st: 64 bit Stata for the Mac /feature request** - Previous by thread:
**RE: st: using different macros everytime** - Next by thread:
**RE: st: using different macros everytime** - Index(es):

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