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

st: Re: repeating analysis for groups

From   Christopher F Baum <>
Subject   st: Re: repeating analysis for groups
Date   Sun, 3 Aug 2003 09:33:02 -0400

On Saturday, August 2, 2003, at 02:33 AM, Fred wrote:

There are a number of approaches you can use:

1) bys group: tab race * etc */

2) forvalues i = 1/ [put the highest value of group here]{
       */ all of your analyses here */
       tab race     if group == `i'
       tab sex      if group ==`i'
       tab race sex if group == `i'

Let's say you have groups defined by three-digit SIC codes, which are not consecutive integers, and you want to do more than one thing per group (e.g. run a regression and save the predicted values). Approach 1 will not work, nor will approach 2. A variation on approach 2 is to use foreach:

webuse auto
levels mpg, local(mpgs)
foreach i of local mpgs {
di _n "For mpg = `i' "
summ price if mpg==`i'
tab rep78 if mpg==`i'


* For searches and help try:

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