Good afternoon,
The cond() function is failing me in a situation where I think it should work.
In my programs I have typically a macro called weights which might contain the weights if the user has specified them, or might be empty if the user has not specified weights.
I am trying the following expression expression with the following purpose: if the user has specified the weights to put them in, and if the user has not specified them to put in 1.
So when the weights are specified, it goes through as it should, e.g.,
But when the macro bla is not defined, instead of giving me 1, the cond() throws an error
I think I know what is happening here, when the macro bla is empty the condition evaluates to
and the third position is empty. Yes, but given that the condition is true, I am not supposed to reach the third position, I am supposed to go to the second position.
The cond() function is failing me in a situation where I think it should work.
In my programs I have typically a macro called weights which might contain the weights if the user has specified them, or might be empty if the user has not specified weights.
I am trying the following expression expression with the following purpose: if the user has specified the weights to put them in, and if the user has not specified them to put in 1.
Code:
gen myweights = cond(missing("`weights'"), 1, `weights')
Code:
. local bla = 3 . dis cond(missing("`bla'"),1,`bla') 3
Code:
. macro drop _all . dis `bla' . dis cond(missing("`bla'"),1,`bla') invalid syntax r(198);
Code:
. dis cond(missing("`bla'"),1,)
Comment