Bookmark and Share

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]

Re: st: reshape query


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: reshape query
Date   Tue, 4 Dec 2012 15:14:21 +0000

What I suggested only solves part of your problem, but what I
suggested was intended only as a stab at what you seemed to be
stumbling on.

It does seem that you need at least one more -reshape long- other than that.

Nick

On Tue, Dec 4, 2012 at 2:31 PM, Tim Evans <[email protected]> wrote:
> 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: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
> Sent: 04 December 2012 13:08
> To: [email protected]
> 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 <[email protected]> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index