Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

RE: AW: AW: st: AW: Generating a dropout dummy variable?


From   Ignacio Martinez <ignacio@virginia.edu>
To   statalist@hsphsun2.harvard.edu
Subject   RE: AW: AW: st: AW: Generating a dropout dummy variable?
Date   Sun, 27 Jun 2010 18:29:03 -0400

I'm not sure what I'm doing wrong. I run
bys (year): egen totaldropouts=total(dropout)
and i get "invalid syntax"

Thanks!
-Ignacio

On Mon, 2010-06-28 at 00:04 +0200, Martin Weiss wrote:
> <>
> Thanks for the flowers.
> 
> I bet your code does what you want. The only issue is that the result is ephemeral. So you may want to try -egen, total()- to make it permanent.
> 
>  Also note you can telescope your two lines via -bysort-.
> 
> HTH
> Martin
> 
> -original message-
> Subject: RE: AW: AW: st: AW: Generating a dropout dummy variable?
> From: Ignacio Martinez <ignacio@virginia.edu>
> Date: 27-06-2010 23:56
> 
> You are so awesome!!!
> 
> I understand the code and is doing what i need it to do.
> 
> One final thing. I want to know the total of dropouts in each year. So
> what I'm doing is:
> sort year
> by year: count if dropout==1
> 
> Is this ok? Is there a better / more elegant way of doing this?
> 
> THANKS!!!!
> 
> -Ignacio
> 
> 
> On Sun, 2010-06-27 at 23:37 +0200, Martin Weiss wrote:
> > <>
> > 
> > ***********
> > //generate an indicator ==1 if is the last time i see the individual
> > bys id (year): gen byte lasttime=_n==_N
> > 
> > //Then i need to create the dropout indicator following the rule that if
> > //last year ==1 and graduated!=1 then dropout==1
> > gen byte dropout=lasttime & graduated!=1
> > ***********
> > 
> > These two lines could be telescoped into one, but I wanted to show the process more comprehensively. 
> > 
> > 
> > HTH
> > Martin
> > 
> > 
> > -----Original Message-----
> > From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ignacio Martinez
> > Sent: Sonntag, 27. Juni 2010 23:13
> > To: statalist@hsphsun2.harvard.edu
> > Subject: Re: AW: AW: st: AW: Generating a dropout dummy variable?
> > 
> > Now I think I finally know what I need to do.
> > 
> > First I need to generate an indicator ==1 if is the last time i see the
> > individual (for example for id=1 if the last time i see him is t=2002
> > then the indicator ==1 in 2002 and ==0 in the other periods)
> > Then i need to create the dropout indicator following the rule that if
> > last year ==1 and graduated!=1 then dropout==1
> > 
> > I think this is going to work, but I'm not sure how to code it. 
> > 
> > Thanks for the help!!!
> > 
> > -Ignacio
> > 
> > 
> > On Sun, 2010-06-27 at 20:22 +0200, Martin Weiss wrote:
> > > <> 
> > > 
> > > 
> > > "So the code should do something like: when is the first time I see the
> > > student. Do I see him after the first time. Was he graduated the last
> > > time i saw him."
> > > 
> > > 
> > > 
> > > The answers to these questions are quite easily obtained, actually:
> > > 
> > > 
> > > *************
> > > //Create data
> > > clear*
> > > set obs 1000
> > > set seed 43550
> > > 
> > > //id
> > > gen int id=_n
> > > //random start year
> > > gen startyear=1999+irecode(runiform(),0,.2,.5,.7,1)
> > > 
> > > //expand to # of time periods
> > > expand 7
> > > 
> > > bys id: gen int year=_n-1+startyear
> > > gen byte graduated=  /* 
> > > */ runiform()<0.3
> > > 
> > > drop if runiform()<.3
> > > 
> > > //throw out twice graduated guys
> > > bys id: egen mytotal=total(graduated)
> > > drop if mytotal>2 & !mi(mytotal)
> > > drop mytotal startyear
> > > drop if year==2009
> > > 
> > > xtset id year
> > > 
> > > 
> > > 
> > > //So the code should do something like:
> > > //when is the first time I see the student?
> > > bys id: egen firstyear=min(year)
> > > 
> > > //Do I see him after the first time?
> > > by id: gen byte afterfirsttime=year>firstyear & /* 
> > > */ !mi(year)
> > > 
> > > //Was he graduated the last time I saw him?
> > > bys id (year): gen byte gradlasttime=(_n==_N)*graduated
> > > 
> > > l in 1/21, sepby(id) noo ab(20)
> > > *************
> > > 
> > > 
> > > 
> > > HTH
> > > Martin
> > > 
> > > 
> > > -----Ursprüngliche Nachricht-----
> > > Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Ignacio Martinez
> > > Gesendet: Sonntag, 27. Juni 2010 19:54
> > > An: statalist@hsphsun2.harvard.edu
> > > Betreff: Re: AW: st: AW: Generating a dropout dummy variable?
> > > 
> > > Thanks
> > > Now i understand better.
> > > 
> > > I think I explain my self wrong the first time so the code is not doing
> > > exactly what I need.
> > > 
> > > My data goes from 2000 to 2008. So is possible that a student enroll in
> > > any year between 2000 and 2008. If I'm understanding the code right I
> > > should change the first line to:
> > > bys id: egen myvar=total(inlist(year,2000,2008))
> > > 
> > > Is this right?
> > > 
> > > But now I'm not sure how should I change the second line.
> > > 
> > > The problem is that some student were enroll for the first time in 2000
> > > some others in 2001, 2002, etc.
> > > 
> > > So the code should do something like: when is the first time I see the
> > > student. Do I see him after the first time. Was he graduated the last
> > > time i saw him. Or something like that
> > > 
> > > Thanks a lot for your help.
> > > 
> > > -Ignacio
> > > 
> > > 
> > > On Sun, 2010-06-27 at 19:38 +0200, Martin Weiss wrote:
> > > > <> 
> > > > 
> > > > " About your code... I'm kind of lost on how you create the dropout
> > > > indicator. Could you explain a little that piece of code?"
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > *************
> > > > //get "dropout" indicator
> > > > 
> > > > //Do I see "id" in 2000 and 2001?
> > > > bys id: egen myvar=total(inlist(year,2000,2001))
> > > > 
> > > > //How many times did I see "id" between 2002 and 2006?
> > > > bys id: egen myvar2=total(inrange(year,2002,2006))
> > > > 
> > > > //dropout is 1 if I saw "id" in 2000 and 2001
> > > > //and did not see him again afterwards
> > > > //and, in 2001, his "graduated" was not 1
> > > > bys id: gen dropout=((myvar==2)*(myvar2==0))& /* 
> > > > */ ((graduated!=1)*(year==2001))
> > > > *************
> > > > 
> > > > 
> > > > See this thread for the tricks re "conditions": http://www.stata.com/statalist/archive/2010-06/msg00985.html
> > > > 
> > > > 
> > > > 
> > > > HTH
> > > > Martin
> > > > 
> > > > 
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Ignacio Martinez
> > > > Gesendet: Sonntag, 27. Juni 2010 19:33
> > > > An: statalist@hsphsun2.harvard.edu
> > > > Betreff: Re: st: AW: Generating a dropout dummy variable?
> > > > 
> > > > About the second part:
> > > > What I was trying to say is that if i see a student in the year 2000 and
> > > > i don't see him in 2001 because he is taking a break but in the year
> > > > 2005 he is back in my sample I don't want to mark him as drop out but I
> > > > want to generate a variable that says that he took a 4 year break.
> > > > 
> > > > About your code... I'm kind of lost on how you create the dropout
> > > > indicator. Could you explain a little that piece of code?
> > > > 
> > > > Thanks a lot
> > > > 
> > > > -Ignacio
> > > > 
> > > > 
> > > > On Sun, 2010-06-27 at 19:01 +0200, Martin Weiss wrote:
> > > > > <> 
> > > > > 
> > > > > The first part could be:
> > > > > 
> > > > > 
> > > > > *************
> > > > > 
> > > > > //Create data
> > > > > clear*
> > > > > set obs 1000
> > > > > set seed 43550
> > > > > 
> > > > > //id
> > > > > gen int id=_n
> > > > > 
> > > > > //expand to # of time periods
> > > > > expand 7
> > > > > 
> > > > > bys id: gen int year=_n+1999
> > > > > gen byte graduated=  /* 
> > > > > */ cond(runiform()<0.3 & year==2001,1,0) 
> > > > > 
> > > > > drop if runiform()<.7
> > > > > 
> > > > > xtset id year
> > > > > 
> > > > > //get "dropout" indicator
> > > > > bys id: egen myvar=total(inlist(year,2000,2001))
> > > > > bys id: egen myvar2=total(inrange(year,2002,2006))
> > > > > bys id: gen dropout=((myvar==2)*(myvar2==0))& /* 
> > > > > */ ((graduated!=1)*(year==2001))
> > > > > drop myvar*
> > > > > 
> > > > > //take a look
> > > > > bys id: egen anydropout=max(dropout)
> > > > > l if anydropout, sepby(id)
> > > > > *************
> > > > > 
> > > > > 
> > > > > I do not understand the second part. Why would dropout be 1 in 2000 if you saw the guy in 2000?
> > > > > 
> > > > > 
> > > > > HTH
> > > > > Martin
> > > > > 
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Ignacio Martinez
> > > > > Gesendet: Sonntag, 27. Juni 2010 15:54
> > > > > An: statalist@hsphsun2.harvard.edu
> > > > > Betreff: st: Generating a dropout dummy variable?
> > > > > 
> > > > > Hi,
> > > > > 
> > > > > 
> > > > > My panel has the following variables: Year (from 2000 to 2008), ID,
> > > > > Graduated (an indicator =1 if the student graduated that year) . 
> > > > > 
> > > > > I want to generate a dropout variable. If I see ID==1111 in year==2000
> > > > > and 2001 but not after that and graduated !=1 in 2001 I want dropout==1
> > > > > in 2001 . The only other detail is that if a see someone in 2000 and
> > > > > then I see him again in 2006 with graduated=1 I don't want dropout =1 in
> > > > > 2000 I want other variable that is break=5 (that student took 5 year of
> > > > > break)
> > > > > 
> > > > > 
> > > > > Thanks for the help
> > > > > 
> > > > > 
> > > > > -Ignacio
> > > > > 
> > > > > 
> > > > > *
> > > > > *   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/
> > > > > 
> > > > > 
> > > > > *
> > > > > *   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/
> > > > 
> > > > 
> > > > *
> > > > *   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/
> > > > 
> > > > 
> > > > *
> > > > *   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/
> > > 
> > > 
> > > *
> > > *   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/
> > > 
> > > 
> > > *
> > > *   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/
> > 
> > 
> > *
> > *   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/
> > 
> > 
> > *
> > *   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/
> 
> 
> *
> *   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/
> 
> 
> *
> *   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/


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index