Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: -replace- suggestions?


From   [email protected]
To   [email protected]
Subject   Re: st: -replace- suggestions?
Date   Wed, 14 Dec 2005 15:12:50 -0600

How about:

levelsof year if con == "A" , local(levels)
foreach l of local levels {
	replace con = "A" if con == "A/B" & year == `l'
}


Scott

----- Original Message -----
From: Terra Curtis <[email protected]>
Date: Wednesday, December 14, 2005 2:23 pm
Subject: st: -replace- suggestions?

> Dear Statalist,
> 
> I am working with a panel dataset of companies.  Company names 
> consist of
> one company, A for example, or two companies, A/B for example, 
> when A and B
> have entered into an agreement.  An example of this data looks like:
> 
> Coname	year        	othervars...
> ------	----        	---------
> A        	1990                	.
> A        	1991                	.	
> A        	1992                	.
> A/B        	1989                	.
> A/B        	1990                	.
> A/B        	1991                	.
> .
> .
> .
> 
> 
> What I would like to do is to replace coname="A" if coname=="A/B" 
> AND (this
> is the part I need help coding) company A also has data for that 
> year.  So
> in the above example, the end result after the replace would be:
> 
> Coname	year        	othervars...
> ------	----        	---------
> A        	1990                	.
> A        	1991                	.	
> A        	1992                	.
> A/B        	1989                	.
> A        	1990                	.
> A        	1991                	.
> .
> .
> .
> 
> Does anyone see how to achieve this?  I think it amounts to having 
> the if
> clause refer to other observation lines (namely, the lines with
> coname=="A"). Thanks in advance for any suggestions.
> 
> -Terra 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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