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

Re: st: Pulling out observations based on a condition

From   Jeph Herrin <>
Subject   Re: st: Pulling out observations based on a condition
Date   Wed, 29 Jul 2009 13:53:33 -0400

1 to 5 or 5 to 1? Or just 1 to 5? Do they have to make the
big jump each period, or at least once over 21 periods? Your
posts have been ambiguous about both. You need to be specific
if you want specific answers.

Here's a modification that gets just the big jumps (either way)
and for each subject counts the number of big jumps; you can then
keep subjects according to whether numbigjumps=20 (the maximum number
of bigjumps) or numbigjumps>=1 or whatever.

  bys id (time) : gen bigjump=(abs(status-status[_n-1])==4)|(_n==1)
  bys id : egen numbigjumps=sum(bigjumps)


Dmitriy Krichevskiy wrote:
Thanks a lot Jeph,
First, to clarify - I would like to keep those that do transition. But
I want to handpick those who transition from state 1 to state 5 - not
just those that leave state 1 to go anywhere. Thanks again, Dmitriy

2009/7/29, Jeph Herrin <>:
By "pull out", do you mean "drop" or "keep"? Here's a way
to keep them. Let -id- identify individuals, -time-
identify periods, and -status- be dichtomous variable of

  /* tag those who transition from period to period */
  bys id (time) : gen transition=(status!=status[_n-1])|(_n==1)

  /* check if individual always transitions */
  bys id : egen alwaystransits=min(transition)

  /* if they always transitioned, notrans==0 */
  keep if alwaystransits

This keeps those who transition between every time period.


Dmitriy Krichevskiy wrote:
Dear Statalisters,

I have a panel data set with about 14000 people and 21 time periods. I
wanted to pull out persons who have transitioned from one category of
the same dichotomous variable to another (say from lowest income
quintile to the highest) during one time increment - for the whole
duration on the sample. So, essentially, I need to pull out all the
people that did that transition from first period to second plus from
second to third and so on... I know it is a simple loop but whatever I
do Stata drops all of the observations. Perhaps, I should also mention
that I am new to programing altogether. Thanks for all of your help,
Statalisters definitely  will be thanked in my dissertation.
*   For searches and help try:

*   For searches and help try:

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