Thanks for the tip about -ds-, that will at least answer
my first question in the something close to affirmative.
And yes, I did simplify in my examples, because I was too
lazy to check my code. Similarly (per Nick's comment), I
know that -summarize if <cond>- was completely out of line,
but thought it was worth a thousand words of trying explain
what I wanted to do.
Had never noticed that feature of -ds-, quite useful. Though
would be nice it was extending to matching particular char
values. Eg,
. ds, has(char scale KCCQ)
thanks,
Jeph
Johannes Geyer wrote:
>> This has been helpful in a lot of programming contexts.
>> For instance, I currently pull out the variables that form
>> the KCCQ survey scale by looping over ALL the variables
>>
>> foreach V of _all {
>> local scale = V[scale]
>> if "`scale'"=="KCCQ" {
>> ...
>> }
>> }
>>
>
> I have a question related to your code:
>
> local scale = V[scale]
>
> does this work or did you simplify?
>
> I get an error message, Stata does not know what
> "scale" is, so I have to write
>
> local scale = "`V[scale]'"
>
> furthermore "V" is a local, the code would be:
>
> local scale = "``V'[scale]'"
>
> You could also use -ds-:
>
> ds, has(char scale)
>
> then the code would read:
>
> /***************/
> qui ds, has(char scale)
> foreach v of varlist `r(varlist)' {
>
> local scale = "``v'[scale]'"
> if "`scale'"=="KCCQ" {
> ...
> }
> }
> /***************/
>
> Johannes
>
>
> *
> * 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/