Statalist


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

Re: st: Wild character in variable names?


From   dr kardos laszlo <[email protected]>
To   [email protected]
Subject   Re: st: Wild character in variable names?
Date   Fri, 16 Jan 2009 11:30:32 +0100

for brevity, you could try this:

unab diagvars1 : diag?
unab diagvars2 : diag??
replace vara=1 if inlist("A",`:subinstr loc diagvars1 " " ",", all') | inlist("A",`:subinstr loc diagvars2 " " ",", all')

the reason why diag* does not work and why you need two -inlist()- evaluations is -inlist()- 's number-of-arguments limit. otherwise you could use diag* and just one instance of -unab-.
hope this helps
laszlo

sdm1 wrote:
I have ten variables called diag1, diag2, ... diag10.

I would like to do a replace such that:

replace vara=1 if diag1=="A" | diag2=="A" | diag3=="A" ... .

I would rather not have to write out all ten conditions. Is there a wild character, like *, I can use in the variable name so that
this works:

replace vara=1 if diag*=="A"

Thanks.

Steve

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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index