Correct.
I guess
bysort state county age race : egen totalmales = total(males * perwt)
by state county age race : egen totalfemales = total(females * perwt)
gen ratio = totalmales / totalfemales
Nick
[email protected]
Scott Cunningham
> On Mar 20, 2006, at 9:42 AM, n j cox wrote:
>
> > You should read some basic accounts of -by:-.
> >
> > Also, please note the advice in the Statalist FAQ:
> >
> > "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?
>
> Sorry about the ambiguity. I did forget my audience. I am working
> with a special sample from the 2000 United States Census called the
> longform. It is a sample of households - I think
> approximately 5% of
> the US population received the survey. An observation is a
> household, but since only 5% of all households were sampled,
> you must
> use the person weights (-perwt-) when working with this data. So,
> for instance, if a certain household is sampled and they represent 5
> households, then the perwt=5. Males and females are numeric values.
>
> >
> > 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-.
>
> I've been using egen to sum males and females, but was unsure of how
> to implement the looping over all US county variables. This
> is where
> -by county- wouuld come in, correct?
*
* 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/