Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: AW: AW: AW: Using if in list of r(...)
From
"Kaulisch, Marc" <[email protected]>
To
<[email protected]>
Subject
st: AW: AW: AW: Using if in list of r(...)
Date
Tue, 6 Apr 2010 15:59:22 +0200
Dear Martin,
Thanks a lot that is a perfect solution.
Marc
-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Martin Weiss
Gesendet: Dienstag, 6. April 2010 15:50
An: [email protected]
Betreff: st: AW: AW: Using if in list of r(...)
<>
As in:
*************
clear*
la def lher 1 "hello" 2 "bye-bye"
la def mylab 1 "hello" 2 "bye-bye"
la def lab 1 "hello" 2 "bye-bye"
la dir
foreach val in `r(names)' {
cap assert substr("`val'",1,1) ~= "l"
if !_rc labelrename `val' `="l"+"`val'"'
}
la dir
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Martin Weiss
Gesendet: Dienstag, 6. April 2010 15:30
An: [email protected]
Betreff: st: AW: Using if in list of r(...)
<>
Note you can -assert- the property, and subsequently condition on the -_rc-:
*************
clear*
la def lher 1 "hello" 2 "bye-bye"
la def mylab 1 "hello" 2 "bye-bye"
la def lab 1 "hello" 2 "bye-bye"
la dir
foreach val in `r(names)' {
cap assert substr("`val'",1,1) ~= "l"
di in r "Now at `val', and rc is: " _rc
}
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Kaulisch, Marc
Gesendet: Dienstag, 6. April 2010 15:05
An: [email protected]
Betreff: st: Using if in list of r(...)
I have the following problem: I would like to have all names of value labels starting with the same prefix "l". But some of the value labels do have already a "l" as a prefix.
I generate the list of value labels ( r(names) )with label dir
But I have not found a way to select only those with if substr("`val'",1,1) ~= "l"
For all value labels it would look like:
foreach val in `r(names)' {
local i = "`val'"
labelrename `i' l`i'
}
But neither foreach, local nor labelrename allow for an if-option. Any hints, ideas?
Thanks,
Marc
*
* 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/
*
* 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/