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: RE: RE: rehape query?
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: RE: RE: RE: rehape query?
Date
Mon, 23 Jul 2012 13:26:30 +0100
Sounds like
rename m sexm
rename f sexf
rename _j agegrp
reshape long sex, i(id agegrp) string
rename sex population
rename _j sex
Nick
[email protected]
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Tim Evans
Sent: 23 July 2012 13:18
To: '[email protected]'
Subject: st: RE: RE: rehape query?
Hi Nick,
Thank you for your response. You are absolutely right, I do have f* for females and m* for males. I tried your example and it worked a treat. I'm struggling on the stacking of the m & f - despite the link to the help article.
I've tried a number of ways to get this, but am struggling:
reshape long m f, i(id _j) j( year) string year already defined -- data already long r(110);
reshape long m f, i(id _j) string
_j already defined -- data already long
r(110);
reshape long m f, i(m f) j(id) string
id already defined -- data already long
r(110);
reshape long m f, i(m f) j(p) string
no xij variables found
r(111);
Other than copying out and pasting over (which I'd prefer not to do), I cant see how I can get it to work.
Best wishes
Tim
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 23 July 2012 12:33
To: '[email protected]'
Subject: st: RE: rehape query?
I see no identifier, so you need one.
gen id = _n
Then you can make progress with
reshape long m , i(id) string
But it seems that you have m* for males; presumably also f* for females. If so, it's probably something like
reshape long m f, i(id) string
followed by another -reshape- stacking the m's and the f's.
See also
FAQ . . . . . . . . . . . . . . . . . . . . . . . . Problems with reshape
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
8/05 I am having problems with the reshape command. Can
you give further guidance?
http://www.stata.com/support/faqs/data/reshape3.html
on creating an identifier when needed and the long-long double -reshape-.
Nick
[email protected]
Tim Evans
Hi, I'm using Stata 11.2.
I have a dataset in the following format:
year dep_val m0004 m0509 m1014
1981 Affluent 536212 595619 719034
1981 Average 278534 299131 364013
1981 Deprived 638771 651976 800071
1982 Affluent 544452 564154 700325
1982 Average 283399 283462 353927
1982 Deprived 652394 618789 776801
1983 Affluent 551374 542624 680392
1983 Average 287977 272890 343038
1983 Deprived 666933 597369 751282
I wish to reconfigure the dataset so that it looks more like this:
Year dep_val sex age_grp pop
1981 Affluent m 0004 536212
1981 Affluent m 0509 595619
1981 Affluent m 1014 719034
1981 Average m 0004 278534
1981 Average m 0509 299131
1981 Average m 1014 364013
I would group the data by year - i.e. 1981, each age_grp in each dep_val.
Does anyone have a solution I could use, which is going to use some aspect of -reshape- I've got a little confused by it.
*
* 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/
_DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.
*
* 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/