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]

RE: st: reshape query


From   Tim Evans <Tim.Evans@wmciu.nhs.uk>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: reshape query
Date   Tue, 4 Dec 2012 14:31:29 +0000

Nick,

I'm still having a little trouble getting my head around this.

Are you saying of the  
Age
Males
mmx
mqx  
mlx     
mdx
mex
Females
fmx
fqx
flx
fdx
fex

I need to rename Males and Females to say genderm/genderf

Or are you saying that for each of these

mmx
mqx  
mlx     
mdx
mex

I need to rename them 
gendermmx
gendermqx  
gendermlx     
gendermdx
gendermex

Followed by 

-reshape long gender, i(id age year) string?

This returns (when only renaming the 'Males/Females' variables:

id	age	year	_j	gender	mmx		mqx		mlx		mdx	mex	fmx	fqx	flx	fdx	fex
1	0	1982	f	Females	.01		.01		100000	1281.7	70.81	.01	.01	100000	994.7	76.8
1	0	1982	m	Males		.01		.01		100000	1281.7	70.81	.01	.01	100000	994.7	76.8
2	1	1982	f	Females	.00087	.000869	98718.3	85.8	70.73	.000724	.000724	99005.3	71.6	76.57
2	1	1982	m	Males		.00087	.000869	98718.3	85.8	70.73	.000724	.000724	99005.3	71.6	76.57

Best wishes

Tim

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: 04 December 2012 13:08
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: reshape query

You want male and female values to be in two observations of the same variable, not two variables for each observation.

At the heart of -reshape- is the idea that that not variable names, but stub names (typically prefixes) indicate what you want. You supplied -m- and -f- as stubnames, so -reshape- takes you at your word. This isn't a problem with -reshape-, as it is doing what you asked. You just need to rename your -m- and -f- to have some common -prefix-, say -genderm- and -genderf- or -gender0- and -gender1-, and then it is a -reshape long-.

On Tue, Dec 4, 2012 at 12:30 PM, Tim Evans <Tim.Evans@wmciu.nhs.uk> wrote:

> I'm using Stata 11.2, and am having a little trouble with -reshape-.
>
> I have a dataset with data as such:
>
> year    age     Males   age     mmx     mqx     mlx             mdx       mex           Females fmx     fqx     flx             fdx     fex
> 1982    0.00    Males   0.00    0.01    0.01    100000.00       1281.70  70.81  Females 0.01    0.01    100000.00       994. 76.80
>
> I want to set the data up so that I have:
>
> Year Sex        age mx  qx      lx              dx              ex
> 1982 Males      0   0.01        0.01    100000.00       1281.70         70.81
> 1982 Females0   0.01    0.01    100000.00       994.0           76.80
>
> I've been trawling a few bits of code that I have used in the past and not finding a solution:
>
>
> g id=_n
> reshape long m f, i(id age year) string
>
>
> But this gives this output:
>
> id      age     year    _j      m               f
> 1       0       1982    dx      1281.7  994.7
> 1       0       1982    ex      70.81           76.8
> 1       0       1982    lx      100000  100000
> 1       0       1982    mx      .0129           .009997
> 1       0       1982    qx      .012817 .009947
>
> I'm sure I probably need another -reshape- around _j
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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