Bookmark and Share

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: Generating patterns from longitudinal data


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Generating patterns from longitudinal data
Date   Thu, 21 Jul 2011 15:46:57 -0500

This is easiest if you think of producing a string variable.

egen var1 = concat(time1 time2 time3 time4)

On tabulation, see also -groups- from SSC. See also -egen-'s -group()-
function with the -label- option.

Nick

On Thu, Jul 21, 2011 at 2:58 PM, Scott Smith <[email protected]> wrote:
>
> I am wondering if there is an efficient method of creating and
> tabulating patterns from longitudinal data. For example, I have four
> waves of data with a dichotomous variable. I want to create a new
> variable that will have each pattern and a count of that pattern.
> There are 16 possible patterns. Instead of doing this:
>
> gen var1=.
> replace var1=0000 if time1==0 & time2==0 & time3==0 & time4==0
> replace var1=1111  if time1==1 & time2==1 & time3==1 & time4==1
>
> and doing that for the remaining 14 patterns (e.g., 0001, 0011, 0111,
> 1010, 0101, etc), is there way of telling stata to do this and store
> it in a new variable? Otherwise, I have to manually do it, and it
> takes a lot of time when I start adding demographics (because I have
> to repeat the code for each level of the demographic variable).
>
> It should look like this when I tab var1 (except for all the patterns):
>
> var1          freq.
>
> 0000         1,000
> 1111          1,050
> 0001            850
>
> I am using stata version 11.2.
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   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/


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