di in red "{p}The {hi:group} option defines a probability. The values defined by this option must be greater (or equal) to 0 and lesser (or equal) to 1.{p_end}"
error 198
exit
}
if "`clear'"==""&"`store'"=="" {
di in red "You must use at least one of these two options: clear and/or store."
error 198
exit
}
if "`dim'"!="" {
local nbdim:word count `dim'
if `nbdim'>2&"`covmatrix'"=="" {
di in red "You can simulate data with one or two dimensions, and you have indicated `nbdim' dimensions in the {hi:dim} option. Please correct it."
error 198
exit
}
if "`covmatrix'"!="" {
local nbrowcovm=rowsof(`covmatrix')
if `nbdim'!=`nbrowcovm' {
di in red "{p 0 0 0}You define `nbdim' dimension(s) with the {cmd:dim} option and `nbrowcovm' dimension(s) with the {cmd:covmatrix} option. Please correct that."
error 198
exit
}
}
local nbitems=0
forvalues d=1/`nbdim' {
local dim`d':word `d' of `dim'
local nbitems=`nbitems'+`dim`d''
}
local dim=`nbdim'
if "`diff'"!="" {
local nbdiff:word count `diff'
local tmp:word 1 of `diff'
if "`tmp'"=="gauss"|"`tmp'"=="uniform" {
local typediff values
}
else if `nbdiff'!=`nbitems' {
di in red "You have indicated a number of difficulty parameters ({hi:diff} option) different of the number of items to simulate ({hi:dim} option). Please correct these options."
di in red "{p 0 0 0}You must indicate the number of items to simulate with the {hi:dim}, the {hi:pcm} or the {hi:diff} option(s)."
error 198
exit
}
else if "`covmatrix'"!= "" {
local nbrowcovm=rowsof(`covmatrix')
if `nbrowcovm'>1 {
di in red "{p 0 0 0}You have define `nbrowcovm' dimensions with the {hi:covmatrix} option, but you do not affect each item to a specific dimension using the {hi:dim} option. Please define the {hi:dim} option."
error 198
exit
}
}
else if "`pcm'"!="" {
local nbitems=rowsof(`pcm')
local dim=1
local dim1=`nbitems'
}
else {
local nbdiff:word count `diff'
local nbitems=`nbdiff'
local dim=1
local dim1=`nbitems'
}
}
if (`group'!=0|`deltagroup'!=0)&`dim'!=1 {
di in red "The {hi:group} and the {hi:deltagroup} options are available only with unidimensional simulated data."
di in red "{p 0 0 0}The {hi:prefix} option is incorrect because the number of defined prefixes (`nbprefix') is different of the number of dimensions (`dim'). Please correct it."
error 198
exit
}
if `nbprefix'==`dim' {
forvalues d=1/`dim' {
local prefix`d':word `d' of `prefix'
}
}
else {
forvalues d=1/`dim' {
local tmp:word `d' of A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
di in red "You simulate two dimensions. You must indicate exactly 3 values in the {hi:cov} option (Variance of the first simulated latent trait, Variance of the second simulated latent trait, Covariance between the two simulated latent traits)."
error 198
exit
}
else if `nbcov'==0 {
if `dim'==1 {
local cov "1"
}
else if `dim'==2 {
local cov "1 1 0"
}
local nbcov:word count `cov'
}
if `nbcov'==3 {
local cov1:word 1 of `cov'
local cov2:word 2 of `cov'
local cov3:word 3 of `cov'
local rho=`cov3'/sqrt(`cov1'*`cov2')
if `cov1'<0|`cov2'<0|`rho'<-1|`rho'>1 {
di in red "Your covariance matrix defined by the {hi:cov} option is not correct. Please correct it."
qui replace lt1=lt1+`deltagroup'*(1-`group') if group==1
qui replace lt1=lt1-`deltagroup'*`group' if group==0
qui compress
}
di in gr "Number of individuals: " in ye `nbobs'
di
if "`threshold'"=="" {
local line di in gr "{hline 75}"
}
else {
local line di in gr "{hline 27}"
}
if "`threshold'"=="" {
`line'
di _col(1) in gr "Items" _col(18) "Difficulty" _col(34) "Discr." _col(45) "Pmin" _col(58) "Pmax" _col(73) "Acc"
}
else {
`line'
di _col(1) in gr "Items" _col(18) "Difficulty"
}
local dim0=0
local deb1=1
local fin0=0
local fin1=`dim1'
forvalues d=1/`dim' { /* FOREACH DIMENSION*/
local deb`d'=`fin`=`d'-1''+1
local fin`d'=`deb`d''+`dim`d''-1
`line'
local p=`d'-1
local q=1
forvalues i=`deb`d''/`fin`d'' { /*FOREACH ITEM*/
qui compress
tempname prob`i'_`=`nbmodas`i''+1'
qui gen `prob`i'_`=`nbmodas`i''+1''=0
local tau0=0
local tau1=`pcm'[`i',1]
local D "1+exp(`matdisc'[`i',1]*(lt`d'-`tau1'))"
forvalues k=2/`nbmodas`i'' {
local tau`k'=`tau`=`k'-1''+`pcm'[`i',`k']
local D "`D'+exp(`matdisc'[`i',1]*(`k'*lt`d'-`tau`k'')) "
}
if "`threshold'"=="" {
tempname icc`i'
qui gen `icc`i''=0
tempname proba`i'_0
gen `proba`i'_0'=1
forvalues k=`nbmodas`i''(-1)1 {
tempname prob`i'_`k' proba`i'_`k'
qui gen `proba`i'_`k''=`matpmin'[`i',1]+(`matpmax'[`i',1]-`matpmin'[`i',1])*(exp(`matdisc'[`i',1]*(`k'*lt`d'-`tau`k''))/(`D'))^`matacc'[`i',1]
qui replace `proba`i'_0'=`proba`i'_0'-`proba`i'_`k''
qui gen `prob`i'_`k''=`proba`i'_`k''+`prob`i'_`=`k'+1''
qui replace `icc`i''=`icc`i''+`k'*`proba`i'_`k''
qui compress
if "`genproba'"!="" {
qui gen proba`i'_`k'=`prob`i'_`k''-`prob`i'_`=`k'+1''
}
}
if "`genicc'"!="" {
qui gen icc`i'=`icc`i''
}
qui gen `prefix`d''`q'=0
di _col(1) in gr "`prefix`d''`q'" _col(20) in ye %8.4f `pcm'[`i',1] _col(32) %8.4f `matdisc'[`i',1] _col(44) %6.4f `matpmin'[`i',1] _col(56) %6.4f `matpmax'[`i',1] _col(68) %8.4f `matacc'[`i',1]
forvalues k=2/`nbmodas`i'' {
di _col(1) in gr "`prefix`d''`q'_`k'" _col(20) in ye %8.4f `pcm'[`i',`k']
}
tempname uni
qui gen `uni'=uniform()
forvalues k=1/`nbmodas`i'' {
qui replace `prefix`d''`q'=`k' if `uni'<=`prob`i'_`k''
qui compress
}
}
else { /*if "`threshold'"!=""*/
qui gen `prefix`d''`q'=lt`d'>`pcm'[`i',1]
local tmp=0
forvalues k=1/`nbmodas`i'' {
di _col(1) in gr "`prefix`d''`q'_`k'" _col(20) in ye %8.4f `pcm'[`i',`k']