Statalist


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

RE: st: replace in paneldata at specific dates


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: replace in paneldata at specific dates
Date   Mon, 16 Mar 2009 12:51:18 -0000

It does no harm to insist that observations are ordered by date within
identifier: 

bys id (comm_date): replace result = "DM SUCCESS" if result=="NA" &
concept=="veil" & abonaa=="FRIHET" & result[_N]=="SUCCESS"

Looking through very recent threads would uncover several examples of
the same technique. 

Nick 
[email protected] 

Martin Weiss

********clear*

inp id str15 result str15 concept str15 abonaa str15 comm_date
300 Ei-svar veil FRIHET 30mar2008 
300 Ei-svar veil FRIHET 19may2008 
300 NA veil FRIHET 10jun2008
400 Ei-svar veil FRIHET 30mar2008 
400 Ei-svar veil FRIHET 19may2008 
400 NA veil FRIHET 10jun2008
400 FAILURE veil FRIHET 03nov2008 
400 FAILURE veil FRIHET 17dec2008 
400 SUCCESS veil FRIHET 14jan2009
end


bys id: replace result = "DM SUCCESS" if result=="NA" & concept=="veil"
& abonaa=="FRIHET" & result[_N]=="SUCCESS"

l, noo sepby(id)
*********

[email protected]

> I have a panel of data that looks like this,
> 
> id	result	consept	abonaa	comm_date
> 400	Ei-svar	veil		FRIHET	30mar2008 
> 400	Ei-svar	veil		FRIHET	19may2008 
> 400	NA		veil		FRIHET	10jun2008
> 400	FAILURE	veil		FRIHET	03nov2008 
> 400	FAILURE	veil		FRIHET	17dec2008 
> 400	SUCCESS	veil		FRIHET	14jan2009
> 
> I would like to recode the variable result = "DM SUCCESS" if
result==NA,
> concept="veil" and abonaa="FRIHET", but only if the last comm_date for
every
> member of the panel is not equal to SUCCESS in the variable result. In
> this case result = SUCCESS for comm_date=14jan2009, thus result="NA"
stays
> equal to NA. 
> 
> However, in this example,
> 
> id	result	consept	abonaa	comm_date
> 300	Ei-svar	veil		FRIHET	30mar2008 
> 300	Ei-svar	veil		FRIHET	19may2008 
> 300	NA		veil		FRIHET	10jun2008
> 
> result=NA occurs at the last comm_date for id=300 thus I want to
recode NA
> = "DM SUCCESS"

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