Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Collapseing by year

From   Nick Cox <>
To   "''" <>
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. 


Alan Neustadtl

Something like the following might work for you:

  gen yearTMP=birth_year
  collapse (count) nbirths=yearTMP, by(birth_year)

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

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
<> 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:

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