First code for accounting DIF scenarios (stata)
parent
db17ae474c
commit
6a5c600b70
@ -1,55 +1,77 @@
|
|||||||
*=================================================================================================================================================
|
*=================================================================================================================================================
|
||||||
* Date : 2024-01-23
|
* Date : 2024-01-23
|
||||||
* Stata version : Stata 18 SE
|
* Stata version : Stata 18 SE
|
||||||
*
|
*
|
||||||
* This program analyses simulated data accounting for DIF through a partial credit model
|
* This program analyses simulated data accounting for DIF through a partial credit model
|
||||||
*
|
*
|
||||||
* ado-files needed : - pcm (version 5.5 October 25, 2023, available on gitea)
|
* ado-files needed : - pcm (version 5.5 October 25, 2023, available on gitea)
|
||||||
*
|
*
|
||||||
* outputs : for N=100
|
* outputs : for N=100
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*================================================================================================================================================
|
*================================================================================================================================================
|
||||||
|
|
||||||
* Load pcm.ado
|
* Load pcm.ado
|
||||||
adopath+"/home/corentin/Documents/These/Recherche/Simulations/Modules/"
|
adopath+"/home/corentin/Documents/These/Recherche/Simulations/Modules/"
|
||||||
|
|
||||||
* Set output folder path
|
|
||||||
local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N100"
|
|
||||||
local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/NoDIF/N100"
|
|
||||||
local Nn = 100
|
|
||||||
|
|
||||||
|
|
||||||
*==========================
|
*==========================
|
||||||
* Scenarios with : J=4
|
* Scenarios with : J=4
|
||||||
*==========================
|
*==========================
|
||||||
|
|
||||||
** Scenario 1: J = 4 items / M = 2 modalities
|
** Scenario 5: J = 4 items / M = 2 modalities / DIF size 0.3
|
||||||
|
local N = "100 200 300"
|
||||||
* Scenario 1A : H_0 is TRUE
|
foreach Nnn in `N' {
|
||||||
|
local Nn = `Nnn'
|
||||||
|
local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
|
||||||
|
local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'"
|
||||||
|
local scenarios = "A B C D E"
|
||||||
|
foreach scen in `scenarios' {
|
||||||
clear
|
clear
|
||||||
import delim "`path_data'/scenario_5A_100.csv", encoding(ISO-8859-2) case(preserve) clear
|
import delim "`path_data'/scenario_5`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
|
||||||
rename TT tt
|
rename TT tt
|
||||||
|
|
||||||
|
* Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif
|
||||||
|
local nbitems = 4
|
||||||
keep if replication==1
|
local nbdif = 1
|
||||||
di `k'
|
local taillemat = `nbitems'+`nbdif'+3
|
||||||
* log using gsem.txt, text replace
|
mat outmat = J(1000,`taillemat',.)
|
||||||
* Créer une matrice 1000xnbitems+1 (pour beta) à l'avance et populer chaque coefficient à la main à chaque itération
|
mat colnames outmat = "item1" "item2" "item3" "item4" "dif1" "beta" "se_beta" "dif_item_1"
|
||||||
* Créer une deuxième matrice et faire de même pour les std error
|
di "Scenario 5`scen' / N=`Nnn'"
|
||||||
gsem (1.item1<-THETA@1)///
|
forvalues k=1/1000 {
|
||||||
(1.item2<-THETA@1 tt)///
|
if (mod(`k',100)==0) {
|
||||||
(1.item3<-THETA@1 )///
|
di "`k'/1000"
|
||||||
(1.item4<-THETA@1)///
|
}
|
||||||
(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent
|
preserve
|
||||||
|
qui keep if replication==`k'
|
||||||
|
local difitems1=dif1
|
||||||
|
local mod "gsem "
|
||||||
|
forvalues i=1/`nbitems' {
|
||||||
|
if (`i'==`difitems1') {
|
||||||
|
local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
local mod = "`mod'"+"(1.item`i'<-THETA@1)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
|
||||||
|
qui `mod'
|
||||||
mat V=r(table)
|
mat V=r(table)
|
||||||
mat W=V[1..2,1...]
|
mat W=V[1..2,1...]
|
||||||
putexcel set "W.xls", sheet("W") replace
|
forvalues j=1/`nbitems' {
|
||||||
putexcel A1=matrix(W)
|
if (`j'<`difitems1') {
|
||||||
* log close
|
mat outmat[`k',`j'] = W[1,3*`j'] // items avant le premier dif
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mat outmat[`k',`j'] = W[1,1+3*`j'] // items après le premier dif
|
||||||
pcm item1 item2 item3 item4, categorical(tt)
|
}
|
||||||
|
}
|
||||||
|
mat outmat[`k',`nbitems'+1] = W[1,2*`difitems1'+1] // coef de dif
|
||||||
|
mat outmat[`k',`nbitems'+2] = W[1,3*`nbitems'+2] // beta
|
||||||
|
mat outmat[`k',`nbitems'+3] = W[2,3*`nbitems'+2] // se beta
|
||||||
|
mat outmat[`k',`nbitems'+4] = `difitems1' // numéro item de dif
|
||||||
|
restore
|
||||||
|
}
|
||||||
|
putexcel set "`path_res'/out/5`scen'_`Nn'.xls", sheet("outmat") replace
|
||||||
|
putexcel A1=matrix(outmat), colnames
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue