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

Re: st: not repeating the 'if' command

From   "Dimitriy V. Masterov" <>
Subject   Re: st: not repeating the 'if' command
Date   Fri, 1 Aug 2003 13:19:09 -0500 (CDT)

I have found something like this to be useful:

bys group: tab race
bys group: tab race sex

bys is shorthand for "by" plus "sort".

Alternatively, you can do something like this:

sum group
scalar min=r(min)
scalar max=r(max)

local i=min
	while `i'<=max {
		display _newline(2) "group is `i'"
		tab race if group==`i'
		tab sex if group==`i'
		tab race sex if group==`i'
	local i=`i'+1

Scalar min and max are defined as the min and max of your group variable.
In your case, min is 1 and max is 50. You could have specified them
yourself instead of defining a scalar. The loop goes trough your group
variable and executes commands based for each group i.

I hope that helps.

Dimitriy Masterov

On Fri, 1 Aug 2003, Robert Bozick wrote:

> I know that in SPSS there is way to set a filter for a series of commands using a 'do if' statement.  Is there a way to do this in STATA?  For example, I want to perform a large set of analyses on a set of groups (group == == 50).  Do I have to continue to type if group == 1 after each command?  ex:
> tab race     if group == 1
> tab sex      if group == 1
> tab race sex if group == 1
> tab race     if group == 2
> tab sex      if group == 2
> tab race sex if group == 2
> or, is there a way to globally set off group == 1 for all analyses then a command to globally set off group == 2 for all analyses, and so on...?   The above code seems too cumbersome.
> *
> *   For searches and help try:
> *
> *
> *

Dimitriy V. Masterov

Center for Social Program Evaluation
1155 East 60th St. Room 038
Chicago, IL 60637
Work: (773)256-6005
Fax: (773)256-6313

1312 East 53rd St., Apt.309
Chicago, IL 60615
Mobile: (773)220-2760

*   For searches and help try:

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