You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
4.5 KiB
Plaintext

// MERGE des modalités si non représentées
forvalues j = 1 / `nbitems' {
local recoda_`j' = 0
qui tab `item`j'' if `tt' == 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 `item`j'' if `tt' == 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]
local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1') // Info moda pour l'item j
local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1')
local nbm_`j' = 4
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 `item`j'' = `r' if `item`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 `item`j'' == `m' & `tt' == 0
local nb_rn1_g0 = r(N)
qui count if `item`j'' == `m' & `tt' == 1
local nb_rn1_g1 = r(N)
local nb_rn = min(`nb_rn1_g0',`nb_rn1_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'_t1_g1' { // La moda 0 n'est pas utilisée
local stop = 1
forvalues k = 1/`=`nbm_`j''-`m'' {
qui count if `item`j'' == `=`m' + `k'' & `tt' == 0
local v`k'1_0 = r(N)
qui count if `item`j'' == `=`m' + `k'' & `tt' == 1
local v`k'1_1 = r(N)
if (`v`k'1_0' != 0 | `v`k'1_1' != 0) & `stop' != 0 {
qui replace `item`j''= `=`m'+`k'' if `item`j''==`m'
qui replace ``=`j'+`nbitems'''=`=`m'+`k'' if ``=`j'+`nbitems'''==`m'
di "WARNING: items `item`j'' & ``=`j'+`nbitems''': answers `m' and `=`m'+`k'' merged"
local stop = 0
}
}
}
else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' { // La moda max n'est pas utilisée
local stop = 1
forvalues k = 1/`=`m'' {
qui count if `item`j'' == `=`m' - `k'' & `tt' == 0
local v`k'1_0 = r(N)
qui count if `item`j'' == `=`m' - `k'' & `tt' == 1
local v`k'1_1 = r(N)
if (`v`k'1_0' != 0 | `v`k'1_1' != 0) & `stop' != 0 {
qui replace `item`j''= `=`m' - `k'' if `item`j''==`m'
qui replace ``=`j'+`nbitems'''= `=`m' - `k'' if ``=`j'+`nbitems'''==`m'
di "WARNING: items `item`j'' & ``=`j'+`nbitems''': answers `m' and `=`m'-`k'' merged"
local stop = 0
}
}
}
else { // Moda central non utilisée
if runiform()>0.5{ // Tirage au sort pour regrouper
local stop = 1
forvalues k = 1/`m' {
qui count if `item`j'' == `=`m' - `k'' & `tt' == 0
local v`k'1_0 = r(N)
qui count if `item`j'' == `=`m' - `k'' & `tt' == 1
local v`k'1_1 = r(N)
if (`v`k'1_0' != 0 | `v`k'1_1' != 0) & `stop' != 0 {
qui replace `item`j''= `=`m'-`k'' if `item`j''==`m'
qui replace ``=`j'+`nbitems'''=`=`m'-`k'' if ``=`j'+`nbitems'''==`m'
di "WARNING: items `item`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 `item`j'' == `=`m' + `k'' & `tt' == 0
local v`k'1_0 = r(N)
qui count if `item`j'' == `=`m' + `k'' & `tt' == 1
local v`k'1_1 = r(N)
if (`v`k'1_0' != 0 | `v`k'1_1' != 0) & `stop' != 0{
qui replace `item`j''=`=`m' + `k'' if `item`j''==`m'
qui replace ``=`j'+`nbitems'''=`=`m' + `k'' if ``=`j'+`nbitems'''==`m'
di "WARNING: items `item`j'' & ``=`j'+`nbitems''': answers `m' and `=`m'+`k'' merged"
local stop = 0
}
else {
if `stop' != 0 {
qui replace `item`j''= `nbm_`j'' if `item`j''==`m'
qui replace ``=`j'+`nbitems'''= `nbm_`j'' if ``=`j'+`nbitems'''==`m'
di "WARNING: items `item`j'' & ``=`j'+`nbitems''': answers `m' and `nbm_`j'' merged"
local stop = 0
}
}
}
}
}
}
}
}