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
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
RE: st: Collapseing by year
Date
Fri, 20 Jan 2012 14:56:06 +0000
-collapse- is a command, not a function.
Also, check out -contract-. -contract- may look almost redundant given -collapse- but it was written largely because it is a more direct way of doing what it does.
Nick
[email protected]
Alan Neustadtl
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.
On Fri, Jan 20, 2012 at 9:18 AM, Lars Folkestad
<[email protected]> wrote:
> 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.
*
* 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/