## Re: st: looping

You should read some basic accounts of -by:-.

"Statalist is an international list. Please explain details that may make sense only in your own corner of the world."

Some of the details here presuppose knowledge of your local situation, which I guess to be the United States. It is likely that many members of Statalist do not know what "msa" means, for example.

I am still in the dark on what an observation in your dataset looks like, or what it represents. I assume that -males- and -females- are numeric variables, but are they dummies or do they include counts? In either case, what is -perwt- precisely?

Either way, I guess that -egen, total()- with heavy use of -by()- or -by:- is the easiest way to get totals of males and females, after which you get ratios directly. It should take about 3 lines of Stata. The only looping would be that tacit in -egen-.

Nick n.j.cox@durham.ac.uk

>>> Scott Cunningham

I have the following dataset:

perwt year state msa county males females age race

My goal is to create sex ratios (ie ratios of males to females) for each county. I have not attempted this before because the way that I calculated sex ratios for states and cities (ie, msa) was to write a .do file that summed up the person weights (ie, perwt) for each state/msa. This was not so bad for states, but moreso for cities, since there are 350 cities. The number of counties are in the thousands, and since I have to create sex ratios that differ by race, age and year, it would require writing out a very long .do file. So my question is: is there a looping procedure I could use, which would use the county-level variable as the variable that does the operation? For instance, if there were two counties (1 and 2), then the loop would sum all males of the given age-race criteria, all females of the same age-race criteria, take the ratio and record that for county 1, then repeat for county 2, etc.

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

--------------------------------------------------------------------------------

Previous Article (by Date): st: single failure with mulltiple risk periods Dawn Teele Articles sorted by: [Date] [Author] [Subject]

--------------------------------------------------------------------------------

Go to Harvard School of Public Health LWGate Home Page. * * 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/

Tag: