Statalist


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

Re: st: -varlist- using char[]?


From   Johannes Geyer <[email protected]>
To   [email protected]
Subject   Re: st: -varlist- using char[]?
Date   Fri, 14 Nov 2008 11:57:42 +0100

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



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