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: Contract/Collapse Combination Continued
From
[email protected] (Brendan Halpin)
To
[email protected]
Subject
Re: st: Contract/Collapse Combination Continued
Date
Mon, 21 May 2012 23:04:17 +0100
On Mon, May 21 2012, Lucas wrote:
> So, my question was trying to see if one could contract/collapse the
> individual-level data to make it look like Brendan's data, and do so
> such that one line contained counts of both the ENTERCOLL=0 and
> ENTERCOLL=1 cases.
An ordinary collapse across all the variables (including ENTERCOLL) will
get you almost to my beginning format, except that you won't necessarily
have every pair. Here's a (non-tested!) sketch of a method of dealing
with pairs and singletons, assuming the variables are ordered as in your
example:
. // First a simple collapse
. gen n = 1
. collapse (sum) n, by(x1-entercoll)
. // Now deal with non-pairs
. sort x1-entercoll
. by x1-x15: gen nobs = _N
. // Create a duplicate for every singleton
. expand 2 if nobs==1
. // Edit the values in the duplicate accordingly
. by x1-x15: replace n=0 if nobs==1 & _n==1 & entercoll==1
. by x1-x15: replace n=0 if nobs==1 & _n==2 & entercoll==0
. // Now reduce the pairs to a single observation
. gen nno = n
. gen nyes = n[_n+1]
. keep if entercoll==0
. drop n entercoll
Brendan
--
Brendan Halpin, Department of Sociology, University of Limerick, Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F1-009 x 3147
mailto:[email protected] ULSociology on Facebook: http://on.fb.me/fjIK9t
http://teaching.sociology.ul.ie/bhalpin/wordpress twitter:@ULSociology
*
* 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/