有没有办法用terser语法表达这个
if (`avgInc' > 0) {
loc avgIncDec = "increased"
}
else {
loc acgIncDec = "decreased"
}
类似于InlineIf(iif):
loc avgInc = iif((`avgInc' > 0), "increased", "decreased")
答案 0 :(得分:2)
尝试cond
var = if cond(a="value","1","another value")
如果a =“value”var =“1”,则var =“另一个值”
还有其他三元运算符:inrange() inlist()
答案 1 :(得分:1)
以前的回答主要关注cond()
,但包含一些小错误。
loc avgIncDec = cond(`avginc' > 0, "increased", "decreased")
请注意,Stata与许多其他语言一样,使用=
进行分配,使用==
来测试相等性。