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: Collapseing by year
From
Alan Neustadtl <[email protected]>
To
[email protected]
Subject
Re: st: Collapseing by year
Date
Fri, 20 Jan 2012 09:44:29 -0500
Something like the following might work for you:
preserve
gen yearTMP=birth_year
collapse (count) nbirths=yearTMP, by(birth_year)
restore
I wrapped my command in -preserve- and -restore- to test this on my
dataset. You do not necessarily need this, just know that collapse is
destructive.
I could not use the same variable for the counts as for the -by- so I
created a temporary variable (yearTMP) to use for the counts and used
the original variable for the -by-.
Obviously, you will need to change the variable names.
Best,
Alan
On Fri, Jan 20, 2012 at 9:18 AM, Lars Folkestad
<[email protected]> wrote:
> Dear List
>
> I have a dataset where i have patient id and birth year.
> I would like to have my data set up so that i have
>
> Birth year number_of_persons_born_this_year
>
>
> I think i have to use the collapse function, but i cannot figure out how.
>
> Thank you.
>
> lars
>
>
> *
> * 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/