Dear all,
I have a question related the -syntax- command, namely how to accomodate a varlist specified as part of an option to use it later within the program. I am using Stata 13 in Windows 10.
In particular, I am defining a program (called descriptives) which requires a varlist. For the subset of continuous variables (specified in the option continuous() ), I apply a set of commands; for the subset of discrete variables (the remaining variables of the varlist), I apply another sets of commands. A MWE of what I have is
My question is how to turn SOMETHING into a condition that uses the content in the continous() option to specify the continuous variables in the varlist. E.g. say that I have 5 variables, x, y and z which are continuous and w1 and w2 which are discrete. Thus, I would like to specify
so that after accomodating "x y z", SOMETHING turns into
"`var'"=="x" | "`var'"=="y" | "`var'"=="z"
which would tell the program that these are the continous variables and do the appropiate analysis. Maybe there is another way to do this more efficiently that does not imply the conditional branching, which I would appreciate to know.
Thank you
I have a question related the -syntax- command, namely how to accomodate a varlist specified as part of an option to use it later within the program. I am using Stata 13 in Windows 10.
In particular, I am defining a program (called descriptives) which requires a varlist. For the subset of continuous variables (specified in the option continuous() ), I apply a set of commands; for the subset of discrete variables (the remaining variables of the varlist), I apply another sets of commands. A MWE of what I have is
Code:
capture: program drop descriptives program define descriptives version 13 syntax varlist(numeric min=1), CONTinuous(varlist numeric min=1) foreach var of local varlist { if SOMETHING { .... [A set of commands here for the continuous variables] .... } else { .... [Another set of commands here for the discrete variables] .... } } end
Code:
descriptives x w1 y z w2, cont(x y z)
"`var'"=="x" | "`var'"=="y" | "`var'"=="z"
which would tell the program that these are the continous variables and do the appropiate analysis. Maybe there is another way to do this more efficiently that does not imply the conditional branching, which I would appreciate to know.
Thank you
Comment