Hello,
I would like to write a program that creates a random dataset.
My codes are as follows.
********************************************
capture program drop testt
program testt, rclass
version 18.0
syntax, n(integer) expand(integer)
// GENERATE THE RANDOM DATA
clear
set obs `n'
gen id=_n
gen bn=uniform()<0.3
gen bb=uniform()<0.2
gen ab=uniform()<0.4
gen spec = ceil(runiform(0, 5))
forvalues i = 1(1)18 {
generate case`i' = 1
}
reshape long case, i(id) j(case_no)
gen idd=_n
save "test.dta", replace
clear
input transfer cog_chara urination route_d medication agep
1 1 1 0 1 0
0 0 1 1 1 1
1 1 1 1 1 1
1 1 0 1 1 0
1 0 0 1 1 1
1 0 1 1 1 0
1 1 1 0 0 1
1 1 1 1 1 1
0 1 1 0 1 1
1 1 1 1 0 0
1 0 1 0 1 1
1 0 1 1 0 1
0 1 0 1 1 1
0 1 1 1 0 1
1 1 0 1 0 1
1 1 0 0 1 1
0 0 0 0 0 0
0 1 1 1 1 0
end
expand `expand'
egen id = seq(), b(18)
gen idd=_n
save "test1.dta", replace
clear
use "test.dta"
merge 1:1 idd using "test1.dta"
end
testt, n(100) expand(100)
************************************
But, the program fails by issueing the following error message.
. expand `expand'
=exp required
Could anyone please help me how to solve this problem?
Thanks in advance.
I would like to write a program that creates a random dataset.
My codes are as follows.
********************************************
capture program drop testt
program testt, rclass
version 18.0
syntax, n(integer) expand(integer)
// GENERATE THE RANDOM DATA
clear
set obs `n'
gen id=_n
gen bn=uniform()<0.3
gen bb=uniform()<0.2
gen ab=uniform()<0.4
gen spec = ceil(runiform(0, 5))
forvalues i = 1(1)18 {
generate case`i' = 1
}
reshape long case, i(id) j(case_no)
gen idd=_n
save "test.dta", replace
clear
input transfer cog_chara urination route_d medication agep
1 1 1 0 1 0
0 0 1 1 1 1
1 1 1 1 1 1
1 1 0 1 1 0
1 0 0 1 1 1
1 0 1 1 1 0
1 1 1 0 0 1
1 1 1 1 1 1
0 1 1 0 1 1
1 1 1 1 0 0
1 0 1 0 1 1
1 0 1 1 0 1
0 1 0 1 1 1
0 1 1 1 0 1
1 1 0 1 0 1
1 1 0 0 1 1
0 0 0 0 0 0
0 1 1 1 1 0
end
expand `expand'
egen id = seq(), b(18)
gen idd=_n
save "test1.dta", replace
clear
use "test.dta"
merge 1:1 idd using "test1.dta"
end
testt, n(100) expand(100)
************************************
But, the program fails by issueing the following error message.
. expand `expand'
=exp required
Could anyone please help me how to solve this problem?
Thanks in advance.
Comment