Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: new: collapse2

From   Dan Blanchette <>
Subject   Re: st: new: collapse2
Date   Wed, 4 Aug 2004 11:19:05 -0400 (EDT)

How about adding an option to save id variables during the -collapse-?
It would be great if you could do this:

. collapse2 (sum) grams kcal fat , by(personid) id(age gender sampwt stratum psu)

because age, gender etc do not vary within a person's set of observations.

I've been cheating -collapse- to get the same result by doing:

. collapse (sum) grams kcal fat , by(age gender sampwt stratum psu personid)


Dan Blanchette
Applications Analyst Programmer
Carolina Population Center UNC-CH

>From 	  "David Roodman" <>
>To 	  <>
>Subject 	  st: new: collapse2
>Date 	  Tue, 3 Aug 2004 20:50:43 -0400
>I've just released an augented version of Stata's collapse command, called collapse2. The only change is that there are now four new "aggregation" operators:
>first --   first observation in group
>last  --   last
>firstnm -- first non-missing
>lastnm  -- last non-missing
>Data must be tsset to use the operators. I find these convenient for example for converting a panel data set with annual observations to one with decadal observations where I need such variables as initial
>GDP and initial population.
>To install, type "ssc install collapse2". Comments welcome.
>David Roodman
>Center for Global Development

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index