Dear Stata users,
I want to write a command that can execute -egen seq()- function. Its grammar is -genseq newvarname=from to block- where the "from" "to" and "block" are three numbers that correponding to parameters of egen seq() function. My codes are as bellow, however it fails to execute. Can anyone help me to debug and rewrite it. Thank you very much.
I want to write a command that can execute -egen seq()- function. Its grammar is -genseq newvarname=from to block- where the "from" "to" and "block" are three numbers that correponding to parameters of egen seq() function. My codes are as bellow, however it fails to execute. Can anyone help me to debug and rewrite it. Thank you very much.
Code:
*! Written in 2022 August 18
program define genseq
args newvarname first second third
gettoken newvarname 0 : 0, parse("= ") bind
gettoken first 0 : 0, parse("= ")
gettoken second 0 : 0, parse("= ")
gettoken third 0 : 0, parse("= ")
if "`first'`second'`third'"=="" {
display as text "enter first value as number of from(), second value as number of to(), third value as number of block()"
}
set obs `second'/`third'
egen `newvarname'=seq(), from(`first') to(`second') block(`third')
end

Comment