eblog 发表于 2010-2-1 10:56
如果能改成这种格式:ntest 1 8, s(test) 就更好了
*使用了"syntax anything",并约束anything所含的非空格字符只能是0-9,试一下:
cap pr drop mytest
pr mytest
syntax anything [,ns s(str)]
qui{
clear all
token `anything'
if indexnot(subinstr("`*'"," ","",.),"0123456789"){
n di as error "Only positive numbers can be input"
exit
}
if "`2'"==""|"`3'"!=""{
n di as error "Two and only two numbers can be input"
exit
}
if `1'>=`2'|`1'<=0{
n di as error "Second number should > first number > 0"
exit
}
if "`ns'"!=""&"`s'"!=""{
n di as error "ns and s should not be input together"
exit
}
local i=`2'-`1'
set obs `i'
gen x=`1'*`2'
if "`ns'"==""{
if "`s'"!="" save `s',replace
else save test,replace
}
}
end