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 13:07:47 +0000

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