Re: st: RE: Adding regression variables one step at a time using a macro
Date
Wed, 10 Mar 2010 17:33:50 +0000
Many thanks.
On Wed, Mar 10, 2010 at 5:19 PM, Eric Booth <ebooth@ppri.tamu.edu> wrote:
>>
>
> In your example you added just one new variable...if that's what you want you can do this:
>
> *********
> clear
> sysuse auto
>
> tokenize price rep78 foreign weight headroom
> while "`1'" != "" {
> regress mpg length `1' /* if !mi(mpg) & !mi(`1') */
> di "For the cmd: `e(cmdline)'"
> macro shift
> }
> *********
> ((You don't need the missing part but it's in the regression above if you want to uncomment it))
>
>
> If you want to sequentially build the model by adding more variables into the regression, you can add them to a local macro first, e.g.,
>
> *********
> clear
> sysuse auto
>
> tokenize price rep78 foreign weight headroom
> while "`1'" != "" {
> local i `1' `i'
> di "`i'"
> regress mpg length `i'
> di "For the cmd: `e(cmdline)'"
> macro shift
> }
>
> *********
>
> ~ Eric
> __
> Eric A. Booth
> Public Policy Research Institute
> Texas A&M University
> ebooth@ppri.tamu.edu
>
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu on behalf of sara khan
> Sent: Wed 3/10/2010 10:52 AM
> To: statalist
> Subject: st: Adding regression variables one step at a time using a macro
>
> Dear Statalisters
>
> Please could you advise me on how to write a macro so that I can add
> regression variables one step at a time for only non-missing cases. It
> is similar to a forward stepwise except that I want to choose which
> variables I add.
>
> At the moment, I am doing the following:
>
> Model 1
> reg y x1 if y<. & x1<.
>
>
> Model 2 - add another var
> reg y x1 x2 if y<. & x1<. &x2<.
>
> Many thanks
> *
> * 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/