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   Scott Merryman <scott.merryman@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: reshape query
Date   Tue, 4 Dec 2012 07:03:53 -0600

On Tue, Dec 4, 2012 at 6:30 AM, Tim Evans <Tim.Evans@wmciu.nhs.uk> wrote:
> Hi all,
>
> 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
>

Note - you have two variables named age.

clear
input year    age  str5   Males        mmx     mqx     mlx
mdx       mex  str8 Females fmx     fqx     flx             fdx
fex
1982    0.00    "Males"      0.01    0.01    100000.00       1281.70
70.81  "Females" 0.01    0.01    100000.00       994. 76.80
end
rename (Males Females) (sexm sexf)
rename m* *m
rename f* *f
reshape long sex mx qx lx dx ex, i(age year) string
l

Scott
*
*   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