Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: loop over variable groups (not individual variables)


From   Amanda Fu <[email protected]>
To   [email protected]
Subject   st: loop over variable groups (not individual variables)
Date   Thu, 18 Aug 2011 22:13:10 -0400

Hi All,

I would like to loop over the following set of  variable groups (
instead of individual variables). But my syntax gives looping over
individual variables. May I have some suggestion on how to fix my
command? Thank you for your time!

************define variable list *********************
local v1 "va "
local v2 "va vb vc"
local v3 "vd "
local v4 "vd ve vf"
local v5 "vg "
local v6 "vg vh vi"

My goal is to loop over v1,v2,...,v6, like this:
reg va
reg va vb vc
reg vd
reg vd ve vf
reg vg
reg vg vh vi

That is, when it comes to v2, I want to indicate  "va vb vc" together
instead of looping over va vb vc one by one. I have tried the
following 2 ways. But both of them gives loop over each variable,
instead of looping over local list.

********1**************
local i=1
foreach v in `v`i' {
reg y  `v'
local i=`i'+1
}

*********2************
local i=1
foreach v in local v`i' {
reg y `v'
local i=`i'+1
}

Best,
Amanda
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index