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

st: RE: listing multiple info with the by command


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: listing multiple info with the by command
Date   Wed, 30 Jul 2003 16:56:26 +0100

Robert Bozick

> I working on a project with clustered data (students within
> schools).  I need to write a program that produces output
> that I can distribute back to the individual schools to
> inform them about discrepancies in the data they provided.
>
> The variables I am working with are:
> schoolid = school level id
> stuid = student id (social security #)
> discrep1....discrep5 = dummy variables coded 1 if there is
> discrepant information on certain items
>
> Here is what I want to do:
> I want to create a program that lists out student ids for
> each discrepant indicator that is coded 1.
>
> I know that I can write a simple command like:
> by schoolid: list stuid if discrep1 == 1
>
> Two questions:
> (1) How do I write the program so that I can incorporate
> all discrep variables before moving to the next schoolid
> (i.e. so that it will list all student ids when discrep ==
> 1, then when discrep2 == 1, etc. before moving onto the next school)
>
> (2) Is there a command that I include to tell STATA to make
> a page break between each school's id so that I can have a
> separate report for each school that lists out all the
> student ids for each 'discrepant' variable?

(2) Page breaks are between you and your (unspecified) word processing
and text processing software, I believe. What might be
worthwhile is to get Stata to display some marker which makes
sense to that software, say
"\vfill\eject" if you were using TeX, but then my
prior probability that you are using MS Word is 0.9, in
which case I cannot advise.

(1) You could do this

levels schoolid, local(schools)

foreach s of local schools {
	forval i = 1/5 {
		di "{title:-> School `s'}"
		list stuid if schoolid == `s' & discrep`i'
		di
	}
}

OR does it make sense to list all suspect ids together?

egen anydiscrep = rsum(disrep?)

levels schoolid, local(schools)

foreach s of local schools {
	di "{title:-> School `s'}"
	list stuid discrep? if schoolid == `s' & anydiscrep
	di
}

Nick
[email protected]

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