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: Contract/Collapse Combination

From   Lucas <>
Subject   Re: st: Contract/Collapse Combination
Date   Tue, 22 May 2012 08:00:48 -0700


My original note indicated exactly the solution you propose, of doing
it twice and merging.  But this is incredibly risky, because there is
no way to assure every combination appears in both files.  Even the
"zero" option apparently cannot assure this.  Believe me, I tried this
with about 6 variables, and the file sizes do not equate across
runs--not to mention that one has to be pretty certain everything is
sorted exactly right.  I do not know *why* the problem occurred, it
occurred, and perhaps it is that the file is so big, that problems
emerge that do not exist for smaller datasets (e.g., sorted cases fall
out of sorts, as it were).

At any rate, my response was to make an id based on the 6 variables:

gen id=(x1*10000)+(x2*1000)+. . .+(x6) ;

This works for 6 dichotomous variables; it will not work for 15
variables of various types, because the id# will exceed the largest
value allowed in stata.

THUS, it seems a more general solution is needed, that does not
require a later merge.

As for your collapse example, it is unclear, as you start with data
that is already collapsed.  The problem is the data is not collapsed,
and the aim is to get it into the collapsed form.

Thanks a bunch.

On Tue, May 22, 2012 at 7:50 AM, Brendan Halpin <> wrote:
> On Tue, May 22 2012, Lucas wrote:
>> Is there a way to use the contract command and obtain frequencies for
>> TWO variables rather than just ONE?  A corollary question would be, Is
>> there a way to use the contract command and obtain the count of 1's on
>> TWO separate dichotomous variables?
> That is what my example achieves, though using -collapse- instead of
> -contract-.
> Another way of doing it would be to separate the data by entercol, and
> -contract- or -collapse- it twice, once for entercol==1 and once for
> entercol==0, and then merge the resulting files by the 15 crosstab
> variables.
> 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
>    ULSociology on Facebook:
>         twitter:@ULSociology

*   For searches and help try:

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