Statalist The Stata Listserver


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

Re: st: Map logical operator across varlist?


From   [email protected]
To   [email protected]
Subject   Re: st: Map logical operator across varlist?
Date   Wed, 17 Jan 2007 14:57:38 -0600

You might be able to use the extended macro function -subinstr- and -
unab-

For example:
clear
set obs 100
set seed 1234
forv i = 1/10 {
	qui gen x`i' = uniform() 
	qui replace x`i' = . if uniform()<.2
}

unab a: x*
local b: subinstr local a " " " != . & ", all
disp "`b'"
l x* if `b' != .


Scott



----- Original Message -----
From: "Joel J. Adamson" <[email protected]>
Date: Wednesday, January 17, 2007 2:08 pm
Subject: st: Map logical operator across varlist?
To: [email protected]

> Does anyone know how to map a logical operation (e.g., | or &) across
> a list so that I can save myself some typing?
> 
> Let me give you an example (the one that prompted the search for an
> answer):
> 
> I want to list a set of variables, only if an observation  is not 
> missingfor the variables in question.  We usually handle this by 
> constructinga small logical expression:
> 
> l med1 med2 if (med1~=.|med2~=.)
> 
> However, if I have six, or a hundred "med" variables (med*), it would
> be easier (less error-prone) to type:
> 
> l med* if |(med*~=.)
> 
> Where the "|" before the "(" maps the operation onto the expanded 
list
> of variables.
> 

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