Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: re: checking for common data entries across variables


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: re: checking for common data entries across variables
Date   Mon, 23 Apr 2007 20:20:28 -0500

In addition to Ingo's suggestion, you can use the -macrolists- to find the
common set of IDs.  

For example:

clear
input str4 id1 str4 id2
"M101"        "F100"
"F100"        "M101"
"F120"        "F130"
"F145"        "M101"
End

qui {
levelsof id1,local(l1) clean	
levelsof id2, local(l2) clean
local a : list l1 & l2
gen common = .
foreach v of varlist id* {
	foreach l of local a {
		replace common = 1 if  `v' == "`l'"
	}
}
}
l

Scott

> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Devendra Amre
> Sent: Monday, April 23, 2007 1:02 PM
> To: statalist
> Subject: st: re: checking for common data entries across variables
> 
> Sorry the earlier message was incomplete..here the complete question..
> 
> Hi everyone,
> Is there a STATA command similar to VLOOKUP that is available in EXCEL?
> For example, I have a list of IDs as 2 variables. I wish to check if
> any ID listed in var1 are present in var2..here is an example:
> 
> var1           var2
> M101        F100
> F100         M101
> F120         F130
> F145         M101
> 
> IDs M101 and F100 are common..is there some way of tagging these IDs?
> Thanks in advance.
> 
> Devendra
> *
> *   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/


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