di as error "You must enter an even number of items : the first half of the items represents the items at time 1 and the second half the items at time 2"
error 198
exit
}
local nbitems=`nbitems'/2
if "`group'"=="" & "`nodif'"!="" {
di as error "nodif can only be used with the group option ({hi:nodif} option). Please correct this option."
error 198
exit
}
local nbc: word count `group'
if `nbc' >= 2 {
di as error "Only one variable can be used for group option ({hi:group} option). Please correct this option."
error 198
exit
}
/* Vérif qu'il y a 2 groupes si l'option groupe est choisie */
if "`group'"!="" {
qui tab `group'
local nbgrp = r(r)
if `nbgrp' != 2 {
di as error "Only 2 groups are possible for the group option ({hi:group} option). Please correct this option."
error 420
exit
}
}
/* recoder la variable de groupe en 0, 1*/
if "`group'"!="" {
qui tab `gp', matrow(rep)
qui matrix list rep
if rep[1,1]+rep[2,1] != 1 & rep[1,1]*rep[2,1] != 0 {
forvalues i=1/`=rowsof(rep)'{
qui replace `gp'=`i'-1 if `gp'==rep[`i',1]
di "WARNING : `gp' `=rep[`i',1]' is now `gp' `=`i'-1' "
}
}
forvalues g = 0/1 {
qui tab `gp' if `gp' == `g'
local nbp_gp`g' = r(N)
}
}
/*item rename*/
/*
Items au temps 1 : 1 à nbitems ``j''
Items au temps 2 : nbitems à 2*nbitems ``=`j'+`nbitems'''
Si t varie, puis num item : ``=(`t'-1)*`nbitems'+`j'''
*/
local com_z = 0 // Indicatrice de recodage
/*verif modalités répondues*/
if "`gp'" == "" { // Si pas d'option groupe
forvalues j = 1 / `nbitems' {
local recoda_`j' = 0
qui tab ``j'', matrow(rect1_`j') // Récupération des infos moda du temps 1
local minm`j'_t1 = rect1_`j'[1,1]
local maxm`j'_t1 = rect1_`j'[r(r),1]
qui tab ``=`j'+`nbitems''', matrow(rect2_`j') // Récupération des infos moda du temps 2
local minm`j'_t2 = rect2_`j'[1,1]
local maxm`j'_t2 = rect2_`j'[r(r),1]
local minm_`j' = min(`minm`j'_t1',`minm`j'_t2') // Info moda pour l'item j
local maxm_`j' = max(`maxm`j'_t1',`maxm`j'_t2')
local nbm_`j' = `=`maxm_`j''-`minm_`j'''
if `minm_`j'' != 0 & `com_z' == 0 {
local com_z = 1
}
//Recodage des réponses en 0, 1, 2, etc...
forvalues r = 0/`=`maxm_`j''-1' {
qui replace ``j'' = `r' if ``j'' == `=`r'+`minm_`j'''
qui replace ``=`j'+`nbitems''' = `r' if ``=`j'+`nbitems''' == `=`r'+`minm_`j'''
}
// Vérif. Que toutes les modas sont utilisées & concordance entre temps
forvalues m = 0/`nbm_`j'' {
qui count if ``j'' == `m'
local nb_rn1 = r(N)
qui count if ``=`j'+`nbitems''' == `m'
local nb_rn2 = r(N)
local nb_rn = min(`nb_rn1',`nb_rn2')
if `nb_rn' == 0 { // Une moda n'est pas utilisée
local recoda_`j' = 1
if `m' == 0 | `m' <= `minm`j'_t1' | `m' <= `minm`j'_t2' { // La moda 0 ou les moda min ne sont pas utilisées
local stop = 1
forvalues k = 1/`=`nbm_`j''-`m'' {
qui count if ``j'' == `=`m' + `k''
local v`k'1 = r(N)
qui count if ``=`j'+`nbitems''' == `=`m' + `k''
local v`k'2 = r(N)
if (`v`k'1' != 0 | `v`k'2' != 0) & `stop' != 0 {
qui replace ``j''= `=`m'+`k'' if ``j''==`m'
qui replace ``=`j'+`nbitems'''=`=`m'+`k'' if ``=`j'+`nbitems'''==`m'
di "WARNING: items ``j'' & ``=`j'+`nbitems''': answers `m' and `=`m'+`k'' merged "
local stop = 0
}
}
}
else if `m' >= `maxm`j'_t1' | `m' >= `maxm`j'_t2' | `m' == `maxm_`j'' { // La (ou les) moda max ne sont pas utilisée(s)
local stop = 1
forvalues k = 1/`m' {
qui count if ``j'' == `=`m' - `k''
local v`k'1 = r(N)
qui count if ``=`j'+`nbitems''' == `=`m' - `k''
local v`k'2 = r(N)
if (`v`k'1' != 0 | `v`k'2' != 0) & `stop' != 0 {
qui replace ``j''=`=`m' - `k'' if ``j''==`m'
qui replace ``=`j'+`nbitems'''=`=`m' - `k'' if ``=`j'+`nbitems'''==`m'
di "WARNING: items ``j'' & ``=`j'+`nbitems''': answers `m' and `=`m'-`k'' merged"
local stop = 0
}
}
}
else {
if runiform()>0.5{ // Tirage au sort pour regrouper
local stop = 1
forvalues k = 1/`m' {
qui count if ``j'' == `=`m' - `k''
local v`k'1 = r(N)
qui count if ``=`j'+`nbitems''' == `=`m' - `k''
local v`k'2 = r(N)
if (`v`k'1' != 0 | `v`k'2' != 0) & `stop' != 0 {
qui replace ``j''= `=`m'-`k'' if ``j''==`m'
qui replace ``=`j'+`nbitems''' =`=`m'-`k'' if ``=`j'+`nbitems''' ==`m'
di "WARNING: items ``j'' & ``=`j'+`nbitems''': answers `m' and `=`m'-`k'' merged"
local stop = 0
}
}
}
else {
local stop = 1
forvalues k = 1/`=`nbm_`j''-`m'' {
qui count if ``j'' == `=`m' + `k''
local v`k'1 = r(N)
qui count if ``=`j'+`nbitems''' == `=`m' + `k''
local v`k'2 = r(N)
if (`v`k'1' != 0 | `v`k'2' != 0) & `stop' != 0 {
qui replace ``j''=`=`m' + `k'' if ``j''==`m'
qui replace ``=`j'+`nbitems'''=`=`m' + `k'' if ``=`j'+`nbitems'''==`m'
di "WARNING: items ``j'' & ``=`j'+`nbitems''': answers `m' and `=`m'+`k'' merged"
local stop = 0
}
else {
if `stop' != 0 {
qui replace ``j''= `nbm_`j'' if ``j''==`m'
qui replace ``=`j'+`nbitems'''= `nbm_`j'' if ``=`j'+`nbitems'''==`m'
di "WARNING: items ``j'' & ``=`j'+`nbitems''': answers `m' and `nbm_`j'' merged"
local stop = 0
}
}
}
}
}
}
}
}
}
else { // Cas où l'option groupe est utilisée
forvalues j = 1 / `nbitems' {
local recoda_`j' = 0
qui tab ``j'' if `gp' == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j') // Récupération des infos moda du temps 1pour chaque groupe
local minm`j'_t1_g0 = rect1_g0_`j'[1,1]
local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1]
qui tab ``j'' if `gp' == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j')
local minm`j'_t1_g1 = rect1_g1_`j'[1,1]
local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1]
qui tab ``=`j'+`nbitems''' if `gp' == 0, matrow(rect2_g0_`j') matcell(nbrt2_g0_`j') // Récupération des infos moda du temps 2 pour chaque groupe
local minm`j'_t2_g0 = rect2_g0_`j'[1,1]
local maxm`j'_t2_g0 = rect2_g0_`j'[r(r),1]
qui tab ``=`j'+`nbitems''' if `gp' == 1 , matrow(rect2_g1_`j') matcell(nbrt2_g1_`j')
local minm`j'_t2_g1 = rect2_g0_`j'[1,1]
local maxm`j'_t2_g1 = rect2_g0_`j'[r(r),1]
local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t2_g0',`minm`j'_t1_g1',`minm`j'_t2_g1') // Info moda pour l'item j
local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t2_g0',`maxm`j'_t1_g1',`maxm`j'_t2_g1')
local nbm_`j' = `=`maxm_`j''-`minm_`j''+1'
if `minm_`j'' != 0 & `com_z' == 0 {
local com_z = 1
}
//Recodage des réponses en 0, 1, 2, etc...
forvalues r = 0/`=`maxm_`j''-1' {
qui replace ``j'' = `r' if ``j'' == `=`r'+`minm_`j'''
qui replace ``=`j'+`nbitems''' = `r' if ``=`j'+`nbitems''' == `=`r'+`minm_`j'''
}
// Vérif. Que toutes les modas sont utilisées & concordance entre temps
forvalues m = 0/`=`nbm_`j''-1' {
qui count if ``j'' == `m' & `gp' == 0
local nb_rn1_g0 = r(N)
qui count if ``j'' == `m' & `gp' == 1
local nb_rn1_g1 = r(N)
qui count if ``=`j'+`nbitems''' == `m' & `gp' == 0
local nb_rn2_g0 = r(N)
qui count if ``=`j'+`nbitems''' == `m' & `gp' == 1
local nb_rn2_g1 = r(N)
local nb_rn = min(`nb_rn1_g0',`nb_rn2_g0',`nb_rn1_g1',`nb_rn2_g1')
if `nb_rn' == 0 { // Une moda n'est pas utilisée
local recoda_`j' = 1
if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t2_g0' | `m' < `minm`j'_t1_g1' | `m' < `minm`j'_t2_g1' { // La moda 0 n'est pas utilisée
local stop = 1
forvalues k = 1/`=`nbm_`j''-`m'' {
qui count if ``j'' == `=`m' + `k'' & `gp' == 0
local v`k'1_0 = r(N)
qui count if ``j'' == `=`m' + `k'' & `gp' == 1
local v`k'1_1 = r(N)
qui count if ``=`j'+`nbitems''' == `=`m' + `k'' & `gp' == 0
local v`k'2_0 = r(N)
qui count if ``=`j'+`nbitems''' == `=`m' + `k'' & `gp' == 1
while `boucle'<=`=`nbitp'-1' & `stop'==0{ /*on s'arrête quand on a libéré du DIF sur (tous les items-1) ou lorsqu'il n'y a plus de tests significatifs*/
if test_dif_`boucle'[`j',3]<`pajust'{/*si DIF sur item i*/
local ++nbsig
if test_dif_`boucle'[`j',3]<`minpval'{
local minpval=test_dif_`boucle'[`j',3]
local itemdif=`j'
}
}
if "`detail'" != "" {
di as text _col(10) abbrev("``j''",15) as result _col(31) %6.3f test_dif_`boucle'[`j',1] _col(48) test_dif_`boucle'[`j',2] _col(57) %6.4f test_dif_`boucle'[`j',3]
}
}
}
/*si nb de tests significatifs=0, on arrête*/
if `nbsig'==0{
local stop=1
if `boucle' == 1 {
if "`detail'" != "" {
di as text _col(10) "{hline 65}"
di
di as result "No significant test: no difference between groups detected, no DIF detected"
di
}
}
else {
if "`detail'" != ""{
di as text _col(10) "{hline 65}"
di
di as result "No other significant tests"
di
}
}
}
else{/*si nb de tests significatifs>0, mise à jour de la matrice de résultats*/
matrix dif_rc[`itemdif',1]=`boucle'
if "`detail'" != ""{
di as text _col(10) "{hline 65}"
di
di as result "Difference between groups on ``itemdif'' at time 1"
}
if `nbmoda_`itemdif'' > 2 {
if "`detail'" != "" {
di
di %~60s as text "Test of uniform difference"
di _col(10) "{hline 40}"
di _col(10) as text "Chi-square" _col(28) "DF" _col(40) "P-value"
di _col(10) as result %4.2f `=test_difu_`boucle'[`itemdif',1]' _col(28) `=test_difu_`boucle'[`itemdif',2]' _col(40) %4.2f `=test_difu_`boucle'[`itemdif',3]'
di _col(10) as text "{hline 40}"
}
if test_difu_`boucle'[`itemdif',3]<0.05{ /*DIF NU détectée*/
matrix dif_rc[`itemdif',2]=0
di
di as result "``itemdif'' : Non-uniform differences of item difficulties between groups at T1"
di
}
else{/*DIF U détectée*/
matrix dif_rc[`itemdif',2]=`boucle'
di
di as result "``itemdif'' : Uniform differences of item difficulties between groups at T1"
di
}
}
else {
// Différence entre groupes au temps 1 mais slmt 2 moda. donc pas de U ou NU