Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

st: loop over variable groups (not individual variables)

From   Amanda Fu <>
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.

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

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

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index