Saturday, February 25, 2006

Re: st: Looping through a variable list

At 11:30 PM 2/24/2006, craig@pharmacy.arizona.edu wrote: >I would like to loop my estimations through an increasing number of >variables, but I am having difficulty undating my varlist. > >For example, suppose there were four variable (A B C D) and I wish to >estimate x on y where x is one of the four sets: "A", "A B", "A B C", and >"A B C D". > >tokenize "A B C D" >local i = 1 >local x = "" >while i<=4 { >local x = `x'+``i'' >regress y `x' >local i=`i'+1 >}

Try this:

tokenize "A B C D" local i = 1 local x = "" while `i'<=4 { local x `x' ``i'' regress y `x' local i=`i'+1 }

If using Stata 9, you could also use nestreg, e.g.

nestreg: regress y A B C D

This would have the advantage of analyzing the same cases throughout in case some vars have missing data. And, you would get tests comparing the models.

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


Tag:


Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?