Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: creating variables using 'by' for subsets of records


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: creating variables using 'by' for subsets of records
Date   Tue, 23 Feb 2010 21:19:49 +0100

<>

In the absence of example data, it is hard to give you advice. Look at this
calculation of regional unemployment rates:


*******
clear*

//10 regions
set obs 10
gen byte region=_n

//50 indiv per region
expand 50
bys region: gen byte id=_n
gen byte unemployed=runiform()>.9

bys region: gen number=_N
by region: egen numofunempl=total(unemployed)

gen unemprate=numofunempl/number
*******


HTH
Martin


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of John Westbury
Sent: Dienstag, 23. Februar 2010 20:55
To: statalist@hsphsun2.harvard.edu
Subject: st: creating variables using 'by' for subsets of records

Hello,

I have records for individuals by geographic region and wish to aggregate
the records for individuals to records for geographic regions.  I believe I
should create variables for those regions using 'by'.  Ex: by Region gen x =
argument for variable.  I am having difficulty with arguments for variable
x.  For example I wish to create a region variable that expresses a ratio of
count of indicator values for individuals in a region to a count of
individuals in the region and am unsure how to code this.

thanks

John

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index