有没有办法用更简洁的语法来表达这一点
if (`avgInc' > 0) {
loc avgIncDec = "increased"
}
else {
loc acgIncDec = "decreased"
}
类似 InlineIf (iif) 的东西:
loc avgInc = iif((`avgInc' > 0), "increased", "decreased")
有没有办法用更简洁的语法来表达这一点
if (`avgInc' > 0) {
loc avgIncDec = "increased"
}
else {
loc acgIncDec = "decreased"
}
类似 InlineIf (iif) 的东西:
loc avgInc = iif((`avgInc' > 0), "increased", "decreased")
尝试cond
var = if cond(a="value","1","another value")
if a="value" var ="1" else var = "另一个值"
还有其他三元运算符:inrange() inlist()
以前的答案有帮助,cond()
但包含一些小错误。
loc avgIncDec = cond(`avginc' > 0, "increased", "decreased")
请注意,Stata 与许多其他语言一样,使用=
赋值和==
测试相等性。