Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE: Splitting a data set by string labels stored in a variable
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: RE: Splitting a data set by string labels stored in a variable
Date
Fri, 13 Jan 2012 18:54:42 +0000
This is a -reshape- followed by some renaming
. reshape wide value , i(regname year) j(varname) string
. renpfix value
In Stata 12
. rename (value*) (*)
is an alternative to the -renpfix- statement.
Nick
[email protected]
Love Hansson
I am currently doing some research on a dataset which contains
time-series data on a number of variables clustered by geographic
region. However, the dataset is structured in a way that stores the
the observations on all variables in a single value variable, and
keeps a separate name variable with the names of all the variables. To
illustrate, this is the format of the data:
varname regname year value
Label1 Region1 2000 x1
Label1 Region1 2001 y1
Label1 Region2 2000 z1
Label1 Region2 2001 a1
Label2 Region1 2000 x2
Label2 Region1 2001 y2
Label2 Region2 2000 z2
Label2 Region2 2001 a2
Now, this is quite inconvenient, and I am therefore looking for an
easy way to convert this into a data file using the values of the
variable "varname" in the example above as variable names and mapping
the contents of "value" onto these, producing a result like the
following:
regname year Label1 Label2
Region1 2000 x1 x2
Region1 2001 y1 y2
Region2 2000 z1 z2
Region2 2001 a1 a2
*
* 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/