Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: Data manipulation


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: Data manipulation
Date   Thu, 25 Mar 2004 17:42:26 -0000

In fact, the local macro is likely to be unnecessary 
here. 

. stack Rohan Gondor Shire, into(data) clear

. gen country =  word("Rohan Gondor Shire", _stack) 

The bigger problem is there are lots of names, and you 
hit some limit on the length of string. 

. stack <long long list>, into(data) clear
. tokenize <long long list> 
. gen country = "" 
. su _stack, meanonly 
. qui forval i = 1/`r(max)' { 
.	replace country = "``i''" if _stack == `i' 
. }

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Nick Cox
> Sent: 25 March 2004 17:36
> To: [email protected]
> Subject: RE: st: RE: Data manipulation
> 
> 
> One way to do it: 
> 
> Suppose your variable names are 
> 
> Rohan
> Gondor
> Shire 
> 
> Put them in a local macro: 
> 
> . local vars "Rohan Gondor Shire"
> 
> . stack `vars' , into(data) clear
> 
> . gen country =  word("`vars'", _stack) 
> 
> With lots of countries, there are 
> extra tricks. 
> 
> Nick 
> [email protected] 
> 
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[email protected]]On Behalf Of 
> > [email protected]
> > Sent: 25 March 2004 17:26
> > To: [email protected]
> > Subject: Re: st: RE: Data manipulation
> > 
> > 
> > The countries were listed as variable names in the original 
> > data set.  When I
> > stacked the data, I was left with only the stack variable, 
> > and the data stacked
> > with only one variable name.
> > 
> > Justin
> > 
> > Quoting Nick Cox <[email protected]>:
> > 
> > > Please tell us how country names were held originally. 
> > > 
> > > Nick 
> > > [email protected] 
> > > 
> > > [email protected]
> > > > 
> > > > I am trying to manipulate my data in the following way: after 
> > > > stacking my data
> > > > (and losing the data in memory), I am trying to recover the 
> > > > country name.  So
> > > > anytime the stack variable is 1 in the dataset, I want to 
> > > > input a string into
> > > > another variable called "country", when the stack variable is 
> > > > 2 in the dataset,
> > > > I want to input a different string in the "country" variable.
> > > 
> > > *
> > > *   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/
> > > 
> > 
> > 
> > 
> > 
> > 
> > *
> > *   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/
> > 
> 
> *
> *   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/
> 

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