Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: looping


From   Scott Cunningham <[email protected]>
To   [email protected]
Subject   st: looping
Date   Mon, 20 Mar 2006 09:08:51 -0500

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/




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