Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: macro shift


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: macro shift
Date   Tue, 11 May 2004 21:27:56 +0100

Don't use macro shift for this. It's not wrong, 
but you have to worry about low-level details 
which Stata will take care of for you. Just 
use -foreach- to cycle through the variables. 

foreach q of var q* { 
	foreach d of var d* { 
		svytab sex `q', row per ci subpop(`d') 
		... 
	}
} 

or whatever. Your wildcards may differ subtly 
(or even non-subtly) from q* and d*. 

Nick 
[email protected] 

[email protected]

> I would like to use the 'svytab' command for a large number 
> of items from a
> questionnaire, and run these results for a large number of 
> subpopulations
> in my dataset.  This is a survey of high school students, and for each
> item, I would like to run a table by sex and grade level.  The
> subpopulations are the various school districts in the state. 
>  Using 'macro
> shift' I have written a program that will run 'svytab' for 
> each item in the
> questionnaire, but I would like to use 'macro shift' at the 
> same time to
> run the tables for each school district.
> 
> The variables from the questionnaire items are in a local macro called
> 'quest'.  (local quest q1 q2 q3 q4...).
> Each school district is represented by a dichotomous 
> variable, with a '1'
> indicating a respondent from within the particular school 
> district, and a
> '0' indicating a student from a different school district.  The school
> districts are in a local macro called 'district'.  (local 
> district d1 d2 d3
> d4....)
> The output I want is a set of tables for each school district 
> (subpop).
> 
> This is the program I am using to run the tables, without referring to
> subpopulations:
> 
> program define xtab
>    while `1' ~= "" {
>     svytab sex `1', row per ci
>     svytab grade `1', row per ci
>     macro shift
>  }
> end
> 
> The command I use to run all the tables is:
> xtab `quest'
> 
> So the question is, how do I get this program to run all of 
> the tables for
> each of the various subpopulations, without rewriting the 
> program for each
> of the subpopulations?
 

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



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