Statalist


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

Re: st: AW: How to generate a variable equalling an earliest date of action b y individual?


From   Ekaterina Hertog <[email protected]>
To   [email protected]
Subject   Re: st: AW: How to generate a variable equalling an earliest date of action b y individual?
Date   Mon, 21 Sep 2009 21:34:43 +0100

Dear Martin,
Thank you very much for the advice! This last solution definitely produces stable results so solves the problem of outcome variation. I am still designing a way to ensure the code deals correctly with my numerous instances of tied data but so far it seems to work.
Thanks a lot again!
warm regards,
Ekaterina 


In message <000b01ca3947$39d063a0$ad712ae0$@[email protected]> [email protected] writes:
> 
> <> 
> 
> " Out of this dataset I want to keep for each individual the date he or she
> made his first approach and the date he or she was first accepted."
> 
> 
> Ekaterina might also want to try -collapse- for this problem setup:
> 
> 
> *************
> clear*
> 
> inp byte id /* 
> */ str20(dateapproached	dateaccepted	)
> 1	"20.04.2007"		"	        "
> 1	"20.04.2007"		"	        "
> 1	"18.05.2007"		"20.05.2007"
> 1	"18.05.2007"		"	        "
> 2	"19.01.2006"		"	        "
> 2	"20.03.2007"		"24.03.2007"
> 2	"20.03.2007"		"	.        "
> 3	"11.09.2007"		"18.09.2007"
> 3	"11.09.2007"		"15.09.2007"
> 3	"01.10.2007"		"	        "
> 3	"07.11.2007"		"	        "
> 4	"06.06.2007"		"	        "
> 4	"08.07.2007"		"	        "
> end
> 
> replace dateaccepted= /* 
> */ trim(dateaccepted)
> 
> gen dateapproached2= /* 
> */ date(dateapproached, "DMY")
> format dateapproached2 /* 
> */ %tdMonth_DD,_CCYY
> 
> gen dateaccepted2= /* 
> */ date(dateaccepted, "DMY")
> format dateaccepted2 /* 
> */ %tdMonth_DD,_CCYY
> 
> drop dateapproached  /* 
> */ dateaccepted 
> 
> compress
> list, noobs sepby(id)
> 
> collapse (first) dateapproached2  /* 
> */ (firstnm) dateaccepted2,  /* 
> */ by(id)
> 
> list, noobs
> *************
> 
> 
> 
> HTH
> Martin
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: [email protected]
> [mailto:[email protected]] Im Auftrag von Ekaterina
> Hertog
> Gesendet: Samstag, 19. September 2009 18:23
> An: [email protected]
> Betreff: st: How to generate a variable equalling an earliest date of action
> b y individual?
> 
> Dear all,
> I have a dataset of individuals each of whom approaches a number of others
> and after approaching each person is either accepted or rejected. I would
> like to do an event history analysis of how the duration of time it takes
> for an individual to secure an acceptance depends on his or hers individual
> characteristics. 
> The variables I am interested in have the following structure (missing
> dateacceppted means a rejection):
> 
> id	dateapproached	dateaccepted	
> 1	20.04.2007			.
> 1	20.04.2007			.
> 1	18.05.2007		20.05.2007
> 1	18.05.2007			.
> 2	19.01.2006			.
> 2	20.03.2007		24.03.2007
> 2	20.03.2007			.
> 3	11.09.2007		18.09.2007
> 3	11.09.2007		15.09.2007
> 3	01.10.2007			.
> 3	07.11.2007			.
> 4	06.06.2007			.
> 4	08.07.2007			.
> 
> Out of this dataset I want to keep for each individual the date he or she
> made his first approach and the date he or she was first accepted.
> To do so I tried to create a new variable date1accept which for each
> individual has the same value => the date he or she was first accepted.
> After that I dropped all the observations, but the 1st one for each
> individual.
> To do so I used the following code:
> sort id dateaccept
>    foreach X of new date1accept {
>    by id : gen `X' = dateaccept[1]
>     }
> 
> sort id
> by id: gen y=_n
> keep if y==1
> 
> I then ran two tests and Stata confirmed that thes assertions below were
> true:
> /*To check that all the values of date1accept are the same*/
> bysort id (date1accept) : assert date1accept[1] == date1accept[_N] 
> /*To check that dat1accept = the lowest value of dateaccept*/
> bysort id (dateaccept) : assert dat1accept[1] == dateaccept[1] 
> 
> yet something seems to be wrong with my commands, each time I re-run the
> code it comes up with slightly different set of date1accept values. I cannot
> understand where can my code be wrong so my tests do not pick it up.
> Could anyone suggest what might be wrong or offer an alternative solution
> for my problem?
> I will be most grateful for any advice,
> Warm regards,
> Ekaterina
> 
> *
> *   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/

-- 
Ekaterina Hertog (nee Korobtseva)
Nissan Institute of Japanese Studies
27 Winchester Road, Oxford
OX2 6NA


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index