If statement (命令)如果x==stata中的列表
我希望能够编写If statement (命令)如果x==stata中的列表,if-statement,stata,If Statement,Stata,我希望能够编写if表达式,而不必使用大量或“|”运算符。例如: drop if x==1 | x==3 | x==5 | x==7 有没有更简单的方法来编写此ie: drop if x==one of (1,3,5,7) 我知道for循环可以工作,但这不是一个很好的解决方案。您可以使用inlist来实现这一点 sysuse auto tab rep78 Repair | Record 1978 | Freq. Percent Cum
if
表达式,而不必使用大量或“|”运算符。例如:
drop if x==1 | x==3 | x==5 | x==7
有没有更简单的方法来编写此ie:
drop if x==one of (1,3,5,7)
我知道for循环可以工作,但这不是一个很好的解决方案。您可以使用
inlist
来实现这一点
sysuse auto
tab rep78
Repair |
Record 1978 | Freq. Percent Cum.
------------+-----------------------------------
1 | 2 2.90 2.90
2 | 8 11.59 14.49
3 | 30 43.48 57.97
4 | 18 26.09 84.06
5 | 11 15.94 100.00
------------+-----------------------------------
Total | 69 100.00
keep if inlist(rep78,1,2,3)
tab rep78
Repair |
Record 1978 | Freq. Percent Cum.
------------+-----------------------------------
1 | 2 5.00 5.00
2 | 8 20.00 25.00
3 | 30 75.00 100.00
------------+-----------------------------------
Total | 40 100.00