Statalist


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

st: RE: RE: ST: creating new variables from a long list


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: ST: creating new variables from a long list
Date   Thu, 29 Oct 2009 23:45:23 +0100

<>

Having received an email privately from Eric, let me have another stab at
his problem, although an example provided by him would be helpful:


*******
clear*
set obs 92
gen dataset=_n

expand 230
bys dataset: gen smsa=_n

gen crime=100+int(300*runiform())

bys dataset:  /* 
 */ egen rank=rank(crime)
reshape wide crime rank,  /* 
 */ i(smsa) j(dataset)
*******


HTH
Martin


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Martin Weiss
Sent: Donnerstag, 29. Oktober 2009 21:09
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: ST: creating new variables from a long list


<>

The totals could be as easy as a -collapse-:


*******
clear*
set obs 92
gen dataset=_n

expand 230
bys dataset: gen smsa=_n

gen crime=100+int(300*runiform())

collapse (sum) crime, /* 
 */ by(dataset)
*******

which gives you an answer in -long- format (in -reshape- parlance), not wide
as you seem to request...

HTH
Martin


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Eric Uslaner
Sent: Donnerstag, 29. Oktober 2009 20:47
To: statalist@hsphsun2.harvard.edu
Subject: st: ST: creating new variables from a long list

Greetings,

I have a data set of 92 sets of crime rankings by SMSA.  But whoever put
them together made a mess out of them (originally in Excel, but I have them
in Stata).  The data set consists of about 230 SMSAs (standard metropolitan
statistical areas) and their crime totals and ranks in 4 columns: data set
number, SMSA name, total, rank--92 times (one for each data set number) so I
have about 30,000+ entries. 

What I want to do is to create 92 * 2 variables so that the data set would
look like this:

SMSAname total1 rank1 total2 rank2...total92 rank92

ideally using SMSAname only once rather than 92 times.  Any suggestions as
to how to do this would be greatly appreciated.

Thanks much,

Ric




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

*
*   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   |   What's new   |   Site index