Computed theoretical power for N=100 and N=200 scenarios

This commit is contained in:
2024-02-19 18:35:26 +01:00
parent ac9189d26a
commit 238852b08b
704 changed files with 261610 additions and 187 deletions

View File

@ -0,0 +1,16 @@
program define dege
syntax anything [, i(string)]
preserve
if "`i'"=="" {
local i ind
}
qui reshape long `anything',i(`i') j(item)
qui rename `anything' response
qui inspect item
local nbvalues=r(N_unique)
forvalues j=1/`nbvalues' {
qui gen `anything'`j'=item==`j'
qui replace `anything'`j'=-`anything'`j'
}
restore,not
end

View File

@ -0,0 +1,108 @@
*! Delta version 1.5 - 5 March 2008
*! Jean-Benoit Hardouin
************************************************************************************************************
* DELTA: delta coefficient
* Version 1.5: March 5, 2008
*
* Historic
* Version 1 (2007-05-21): Jean-Benoit Hardouin
* Version 1.1 (2007-05-22): Jean-Benoit Hardouin /* if in and possibility to use the score*/
* Version 1.2 (2007-05-22): Jean-Benoit Hardouin /*bug when a score is missing*/
* Version 1.3 (2007-06-16): Jean-Benoit Hardouin /*change in the options*/
* Version 1.4 (2007-07-03): Jean-Benoit Hardouin /*correct a bug in the options*/
* Version 1.5 (2008-03-05): Jean-Benoit Hardouin /*correct a bug in the ci option*/
*
* Jean-benoit Hardouin, Faculty of Pharmaceutical Sciences - University of Nantes - France
* jean-benoit.hardouin@univ-nantes.fr
*
* News about this program : http://www.anaqol.org
* FreeIRT Project : http://www.freeirt.org
*
* Copyright 2007-2008 Jean-Benoit Hardouin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
************************************************************************************************************
program define delta , rclass
version 7.0
syntax varlist(min=1 numeric) [if] [in] [,ci(integer 0) noDots MINscore(int 0) MAXscore(int 0)]
preserve
tempfile deltafile
qui save `deltafile'
if "`if'"!=""|"`in'"!="" {
qui keep `if' `in'
}
local nbitems:word count `varlist'
tokenize `varlist'
local scoremin=`minscore'
local scoremax=`maxscore'
tempvar score
if `nbitems'==1&`scoremax'==0 {
di in red "If you indicate only the score variable, you must define the {cmd:scoremax} option"
error 198
}
else if `nbitems'==1&`scoremax'!=0 {
qui gen `score'=`varlist'
}
else {
qui genscore `varlist',score(`score')
}
qui drop if `score'==.
qui count
local nbind=r(N)
if `scoremax'==0 {
qui su `score'
local scoremax=r(max)
}
tempname error
gen `error'=`score'<`scoremin'|`score'>`scoremax'
qui count if `error'==1
local err=r(N)
if `err'!=0 {
di in red "`err' individuals has(have) a score inferior to `scoremin' or superior to `scoremax'"
error 198
}
local sumsqscore=0
forvalues i=`scoremin'/`scoremax' {
qui count if `score'==`i'
local score`i'=r(N)
local sumsqscore=`sumsqscore'+`score`i''^2
}
local delta=(1+`scoremax')*(`nbind'^2-`sumsqscore')/(`nbind'^2*`scoremax')
di in green "Range of the scores : " in ye `scoremin' in gr "/" in ye `scoremax'
di in green "Number of used individuals : " in ye `nbind'
if `ci'!=0 {
bootstrap delta=r(delta), reps(`ci') nowarn noheader nolegend `dots': delta `varlist' ,minscore(`scoremin') maxscore(`scoremax')
}
else {
display in green "Delta= " in yellow %8.6f `delta'
}
return scalar delta=`delta'
qui use `deltafile',clear
restore,not
end

View File

@ -0,0 +1,250 @@
capture program drop descitems
program descitems
syntax varlist, PARTition(numlist integer >0)
local i = 1
local C = 0
foreach z in `partition' {
local C = `C' + `z'
}
local nbvars : word count `varlist'
if `C' != `nbvars' {
di in red "The sum of the numbers in the partition option is different from the number of variables precised in varlist"
exit 119
}
local i = 1
foreach x in `varlist' {
local var`i' = "`x'"
local `++i'
}
/*
qui su `var1'
local min = r(min)
local max = r(max)
forvalue i=2/`nbvars' {
qui su `var`i''
local minloc = r(min)
local maxloc = r(max)
if `minloc'<`min' local min = `minloc'
if `maxloc'>`max' local max = `maxloc'
}
*/
foreach var in `varlist' {
qui replace `var' = round(`var')
}
local lev = ""
foreach var in `varlist' {
qui levelsof `var', local(levels)
foreach l in `levels' {
if strpos("`lev'","`l'") == 0 {
local lev `lev' `l'
}
}
}
_qsort_index `lev'
local lev = r(slist1)
local i = 1
matrix d = J(`nbvars',4,.)
foreach var in `varlist'{
qui count if missing(`var')
local ct=r(N)
local tx`i'=`ct'/_N
matrix d[`i',1] = `tx`i''
local `i++'
}
matrix rownames d = `varlist'
matrix colnames d = "missing" "alpha" "Hj"
local i = 1
local y = 1
foreach x in `partition' {
if `i' == 1 local s = `x'
else local s = `s' +`x'
local liste = ""
forvalues w = `y'/`s' {
local liste `liste' `var`w''
}
qui capture alpha `liste', asi item std
mat a = r(Alpha)
mat at = a'
qui capture loevh `liste', pairwise
matrix e = r(loevHj)
matrix et = e'
matrix ns = r(nbHjkNS)
matrix nst = ns'
local k = 0
forvalues j = `y'/`s' {
local k = `k'+1
matrix d[`j',2] = at[`k',1]
matrix d[`j',3] = et[`k',1]
matrix d[`j',4] = nst[`k',1]
}
local `i++'
local y = `s'+1
}
/* coupure noms des items */
/*
local i = 1
foreach s in `varlist' {
local len = length("`s'")
if `len' > 10 {
local c = substr("`s'",1,9)
local d = substr("`s'",-1,1)
local var`i' "`c'" "~" "`d'"
}
else local var`i' = "`s'"
*local v `v' `var`i''
local `++i'
}
local max = 3
forvalues i=1/`nbvars' {
local len = length("`var`i''")
if `len' > `max' local max = `len'
}
*/
local i = 1
foreach v in `varlist' {
local var`i' = abbrev("`v'",8)
local `++i'
}
local dec = 10
local col = `dec'
local b : word count `lev'
local i = 1
local j = 1
local y = 1
di in blue _col(`dec') "{bf:Missing}" _c
local col = `col'+11
di in blue _col(`=`col'+2') "{bf:N}" _c
local col = `col'+9
di _col(`col') "{bf:Response categories}" _c
local col = `dec'+18+8*`b'
di _col(`col') "{bf:Alpha}" _c
local col = `col'+9
di _col(`col') "{bf:Loevinger}" _c
local col = `col'+12
di _col(`col') "{bf:Number of}"
local col = `dec'-1
di _col(`col') "{bf:data rate}" _c
local col = `dec'+18
foreach m in `lev' {
di _col(`=`col'+2') "`m'" _c
local col = `col'+8
}
local col = `dec'+17+8*`b'
di as result _col(`col') "- item" _c
local col = `col'+10
di as result _col(`col') "Hj coeff" _c
local col = `col'+12
di as result _col(`col') "NS Hjk"
local ch = `dec'+18+8*`b'+29
di "{hline `ch'}"
local i = 1
foreach x in `varlist' {
local varo`i' = "`x'"
local `++i'
}
local y = 1
foreach p in `partition' {
if `j' == 1 local s = `p'
else local s = `s' +`p'
forvalues z = `y'/`s' {
local col = `dec'
di "{bf:`var`z''}" _c
local t = d[`z',1]
local t : di %8.2f `t'
di _col(`col') "{text:`t'}" _c
qui count if missing(`varo`z'')
local m = r(N)
local N = _N-`m'
local N : di %4.0f `N'
local col = `col'+10
di _col(`col') "{text:`N'}" _c
local col = `col'+8
foreach m in `lev' {
local f = 0
qui levelsof `varo`z'', local(levels)
foreach l in `levels' {
if strpos("`levels'","`m'") == 0 {
local f = 1
}
}
/*if `f' == 1 {
di _col(`=`col'+2') "_" _c
}*/
*else {
qui count if round(`varo`z'') == `m'
local n = r(N)
qui count if `varo`z'' != .
local d = r(N)
local e = `n'/`d'
local e : di %4.2f `e'
if `e' != 0 di _col(`=`col'-1')"{text:`e'}" _c
else di _col(`=`col'-1')"{text: -}" _c
*}
local col = `col'+8
}
local col = `dec'+18+8*`b'
local a = d[`z',2]
local a : di %4.2f `a'
di _col(`=`col'+1') "{text:`a'}" _c
local h = d[`z',3]
local h : di %5.2f `h'
local col = `col'+10
di _col(`=`col'+3') "{text:`h'}" _c
local ns = d[`z',4]
local ns : di %1.0f `ns'
local col = `col'+12
di _col(`=`col'+7') "{text:`ns'}"
}
local `i++'
local `j++'
local y = `s'+1
di "{dup `ch':-}"
}
end
*descitems iociociociociocicocio1-ioc37, part(4 4 7 3 3 4 7 5)
*descitems ptgi1-peur16, part(4 4 7 3 3 4 7 5)
*descitems x1-x30, part(5 5 5 5 5 4 1)

View File

@ -0,0 +1,293 @@
*! Version 1.2 29 August 2019
*! Jean-Benoit Hardouin
************************************************************************************************************
* Stata program : descscale
* Description of a scale and covariates
* Release 1.1 : June 4, 2019
*
*
* Historic :
* Version 1 (April 12, 2019) [Jean-Benoit Hardouin]
* Version 1.1 (June 4, 2019) [Jean-Benoit Hardouin]
* Version 1.2 (August 29, 2019) [Jean-Benoit Hardouin] /*correction of bugs*/
*
* Jean-benoit Hardouin, PhD, Assistant Professor
* Team of Methods in Patient Centered Outcomes and Health Research (INSERM U1246-SPHERE)
* University of Nantes - Faculty of Pharmaceutical Sciences
* France
* jean-benoit.hardouin@anaqol.org
*
*
* News about this program :http://www.anaqol.org
*
* Copyright 2019 Jean-Benoit Hardouin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
***********************************************************************************************************
program define descscale , rclass
version 8.2
syntax varlist [if] [in] [,MIN(int 0) CONTinuous(varlist) CATegorical(varlist) All PARTition(numlist) Large MEAN MAXlevels(int 20)]
preserve
marksample touse,novarlist
label variable `touse' "selection"
tokenize `varlist'
local nbitems: word count `varlist'
if "`partition'"=="" {
local partition `nbitems'
}
local nbdim:word count `partition'
forvalues i=1/`nbdim' {
local nbitemsdim`i': word `i' of `partition'
}
qui count if `touse'
local N=r(N)
local maxr=0
forvalues i=1/`nbitems' {
qui levelsof ``i'' if `touse'
local r`i'=r(r)
qui su ``i'' if `touse'
local max`i'=r(max)
local mean`i'=r(mean)
qui count if ``i''!=0&``i''!=1&``i''!=2&``i''!=3&``i''!=4&``i''!=5&``i''!=6&``i''!=7&``i''!=8&``i''!=9&``i''!=10&``i''!=.
local ninc=r(N)
local ok`i'=1
if `r`i''>11&"`large'"=="" {
di in red "The number of answer categories to the items ``i'' is large (>11). Use the -large- option or correct the list of items."
local ok`i'=0
exit
}
if `ninc'>0 {
di in red "The variable ``i'' has incompatible values with an items (integers between 0 and 10)."
local ok`i'=0
exit
}
if `max`i''>`maxr' {
local maxr `max`i''
}
}
di "maxr=`maxr'"
di
di in green "Number of individuals : " as result `N'
di
di in green "Description of the items"
local long=(`maxr'+1-`min')*8+40
di in green "{hline `long'}"
di in green "Items" _col(23) "Obs" _c
local col=33
forvalues j=`min'/`maxr' {
di _col(`col') "`j'" _c
local col=`col'+8
}
di _col(`col') "." _col(`=`col'+4') "Mean"
di in green "{hline `long'}"
local deb=1
forvalues d=1/`nbdim' {
local loi`d'
*di "local fin=`deb'+`nbitemsdim`d''-1"
local fin=`deb'+`nbitemsdim`d''-1
forvalues i=`deb'/`fin' {
if `ok`i''==1 {
local loi`d' `loi`d'' ``i''
qui count if `touse'&``i''!=.
local k=abbrev("``i''",20)
di in green "`k'" _col(22) as result %4.0f `r(N)' _c
local col=28
forvalues j=`min'/`maxr' {
qui count if `touse'&``i''==`j'
local per=round(`r(N)'/`N'*100, 0.1)
di _col(`col') %5.1f `per' "%" _c
local col=`col'+8
}
qui count if `touse'&``i''==.
local per=round(`r(N)'/`N'*100,0.1)
di _col(`col') %5.1f `per' "%" _col(`=`col'+9') %4.2f `mean`i''
}
}
if `d'!=`nbdim' {
di in green "{dup `long':-}"
}
local deb=`fin'+1
}
di in green "{hline `long'}"
di
di in green "Description of the scores"
local long2=72
di in green "{hline `long2'}"
di in green "Scores" _col(22) "Obs" _col(33) "Mean" _col(40) "Std. Dev." _col(58) "Min" _col(70) "Max"
di in green "{hline `long2'}"
forvalues d=1/`nbdim' {
tempname score`d'
genscore `loi`d'' if `touse', score(`score`d'') `mean' `standardized'
qui su `score`d'' if `touse'
di in green "score`d'" _col(20) as result %5.0f `r(N)' _col(30) %7.2f `r(mean)' _col(42) %7.2f `r(sd)' _col(54) %7.2f `r(min)' _col(66) %7.2f `r(max)'
}
di in green "{hline `long2'}"
if "`continuous'"!="" {
local continuous2
foreach i of varlist `continuous' {
local candidate=1
forvalues j=1/`nbitems' {
if "`i'"=="``j''" {
local candidate=0
}
}
local type : type `i'
local type=substr("`type'",1,3)
if "`type'"=="str" {
local candidate=0
}
if `candidate'==1 {
qui levelsof `i' if `touse'
local r=r(r)
local continuous2 `continuous2' `i'
}
}
local continuous `continuous2'
}
if "`categorical'"!="" {
local categorical2
foreach i of varlist `categorical' {
local candidate=1
forvalues j=1/`nbitems' {
if "`i'"=="``j''" {
local candidate=0
}
}
if `candidate'==1 {
qui levelsof `i' if `touse'
local r=r(r)
local categorical2 `categorical2' `i'
}
}
local categorical `categorical2'
}
if "`all'"!="" {
*local continuous
*local categorial
foreach i of varlist * {
local candidate=1
forvalues j=1/`nbitems' {
if "`i'"=="``j''" {
local candidate=0
}
}
local type : type `i'
local type=substr("`type'",1,3)
if "`type'"=="str" {
local candidate=0
}
qui levelsof `i' if `touse'
local r=r(r)
if `r'>7&`candidate'==1 {
local continuous `continuous' `i'
}
else {
local categorical `categorical' `i'
}
}
}
*di "CONTINUOUS : `continuous'"
*di "CATEGORICAL : `categorical'"
if "`continuous'"!="" {
di
di "Descriptive analysis of continuous covariates"
local long2=72
di in green "{hline `long2'}"
di in green "Variables" _col(22) "Obs" _col(33) "Mean" _col(40) "Std. Dev." _col(58) "Min" _col(70) "Max"
di in green "{hline `long2'}"
foreach i of varlist `continuous' {
qui su `i' if `touse'
local k=abbrev("`i'",18)
*di in green "`k'" _c
di in green "`k'" _col(20) as result %5.0f `r(N)' _col(30) %7.2f `r(mean)' _col(42) %7.2f `r(sd)' _col(54) %7.2f `r(min)' _col(66) %7.2f `r(max)'
}
di in green "{hline `long2'}"
}
if "`categorical'"!="" {
di
*set trace on
di "Descriptive analysis of categorical covariates"
local long2=55
di in green "{hline `long2'}"
di in green "Variables" _col(25) "Levels" _col(37) "Freq." _col(49) "Percent"
di in green "{hline `long2'}"
local nbc: word count `categorical'
local m=1
local nonret
foreach i of varlist `categorical' {
local type : type `i'
local type=substr("`type'",1,3)
qui levelsof `i'
local lev "`r(levels)'"
local nblev=r(r)
if (`maxlevels'>=`nblev') {
local k=abbrev("`i'",20)
di in green "`k'" _c
if "`type'"=="str" {
foreach j in `lev' {
qui count if `touse'&`i'=="`j'"
local k=abbrev("`j'",10)
di _col(21) %10s in green "`k'" as result %5.0f _col(37) `r(N)' %6.2f _col(49) `=`r(N)'/`N'*100' "%"
}
qui count if `touse'&`i'==""
if `r(N)'!=0 {
di as result %5.0f _col(37) `r(N)' %6.2f _col(49) `=`r(N)'/`N'*100' "%"
}
}
else {
foreach j in `lev' {
qui count if `touse'&`i'==`j'
di _col(21) %10s in green "`j'" as result %5.0f _col(37) `r(N)' %6.2f _col(49) `=`r(N)'/`N'*100' "%"
}
qui count if `touse'&`i'==.
if `r(N)'!=0 {
di as result %5.0f _col(37) `r(N)' %6.2f _col(49) `=`r(N)'/`N'*100' "%"
}
}
if `m'==`nbc' {
di in green "{hline `long2'}"
}
else {
di in green "{dup `long2':-}"
}
}
else {
local nonret `nonret' `i'
*di "local nonret `nonret' `i'"
*di "non retenu `i'"
if `m'==`nbc' {
di in green "{hline `long2'}"
}
}
local ++m
}
if "`nonret'"!="" {
di in green "Not described variables (too more levels) : " as result "`nonret'"
}
}
end

View File

@ -0,0 +1,290 @@
*! Version 1.1 4 June 2019
*! Jean-Benoit Hardouin
************************************************************************************************************
* Stata program : descscale
* Description of a scale and covariates
* Release 1.1 : June 4, 2019
*
*
* Historic :
* Version 1 (April 12, 2019) [Jean-Benoit Hardouin]
* Version 1.1 (June 4, 2019) [Jean-Benoit Hardouin]
*
* Jean-benoit Hardouin, PhD, Assistant Professor
* Team of Methods in Patient Centered Outcomes and Health Research (INSERM U1246-SPHERE)
* University of Nantes - Faculty of Pharmaceutical Sciences
* France
* jean-benoit.hardouin@anaqol.org
*
*
* News about this program :http://www.anaqol.org
*
* Copyright 2019 Jean-Benoit Hardouin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
***********************************************************************************************************
program define descscale , rclass
version 8.2
syntax varlist [if] [in] [,MIN(int 0) CONTinuous(varlist) CATegorical(varlist) All PARTition(numlist) Large MEAN MAXlevels(int 20)]
preserve
marksample touse,novarlist
label variable `touse' "selection"
tokenize `varlist'
local nbitems: word count `varlist'
if "`partition'"=="" {
local partition `nbitems'
}
local nbdim:word count `partition'
forvalues i=1/`nbdim' {
local nbitemsdim`i': word `i' of `partition'
}
qui count if `touse'
local N=r(N)
local maxr=0
forvalues i=1/`nbitems' {
qui levelsof ``i'' if `touse'
local r`i'=r(r)
qui su ``i'' if `touse'
local max`i'=r(max)
local mean`i'=r(mean)
qui count if ``i''!=0&``i''!=1&``i''!=2&``i''!=3&``i''!=4&``i''!=5&``i''!=6&``i''!=7&``i''!=8&``i''!=9&``i''!=10&``i''!=.
local ninc=r(N)
local ok`i'=1
if `r`i''>11&"`large'"=="" {
di in red "The number of answer categories to the items ``i'' is large (>11). Use the -large- option or correct the list of items."
local ok`i'=0
exit
}
if `ninc'>0 {
di in red "The variable ``i'' has incompatible values with an items (integers between 0 and 10)."
local ok`i'=0
exit
}
if `r`i''>`maxr' {
local maxr `r`i''
}
}
*di "maxr=`maxr'"
di
di in green "Number of individuals : " as result `N'
di
di in green "Decription of the items"
local long=(`maxr'+1-`min')*8+40
di in green "{hline `long'}"
di in green "Items" _col(23) "Obs" _c
local col=33
forvalues j=`min'/`maxr' {
di _col(`col') "`j'" _c
local col=`col'+8
}
di _col(`col') "." _col(`=`col'+4') "Mean"
di in green "{hline `long'}"
local deb=1
forvalues d=1/`nbdim' {
local loi`d'
*di "local fin=`deb'+`nbitemsdim`d''-1"
local fin=`deb'+`nbitemsdim`d''-1
forvalues i=`deb'/`fin' {
if `ok`i''==1 {
local loi`d' `loi`d'' ``i''
qui count if `touse'&``i''!=.
local k=abbrev("``i''",20)
di in green "`k'" _col(22) as result %4.0f `r(N)' _c
local col=28
forvalues j=`min'/`maxr' {
qui count if `touse'&``i''==`j'
local per=round(`r(N)'/`N'*100, 0.1)
di _col(`col') %5.1f `per' "%" _c
local col=`col'+8
}
qui count if `touse'&``i''==.
local per=round(`r(N)'/`N'*100,0.1)
di _col(`col') %5.1f `per' "%" _col(`=`col'+9') %4.2f `mean`i''
}
}
if `d'!=`nbdim' {
di in green "{dup `long':-}"
}
local deb=`fin'+1
}
di in green "{hline `long'}"
di
di in green "Decription of the scores"
local long2=72
di in green "{hline `long2'}"
di in green "Scores" _col(22) "Obs" _col(33) "Mean" _col(40) "Std. Dev." _col(58) "Min" _col(70) "Max"
di in green "{hline `long2'}"
forvalues d=1/`nbdim' {
tempname score`d'
genscore `loi`d'' if `touse', score(`score`d'') `mean' `standardized'
qui su `score`d'' if `touse'
di in green "score`d'" _col(20) as result %5.0f `r(N)' _col(30) %7.2f `r(mean)' _col(42) %7.2f `r(sd)' _col(54) %7.2f `r(min)' _col(66) %7.2f `r(max)'
}
di in green "{hline `long2'}"
if "`continuous'"!=""|"`categorical'"!="" {
local continuous2
foreach i of varlist `continuous' {
local candidate=1
forvalues j=1/`nbitems' {
if "`i'"=="``j''" {
local candidate=0
}
}
local type : type `i'
local type=substr("`type'",1,3)
if "`type'"=="str" {
local candidate=0
}
if `candidate'==1 {
qui levelsof `i' if `touse'
local r=r(r)
local continuous2 `continuous2' `i'
}
}
local continuous `continuous2'
local categorical2
foreach i of varlist `categorical' {
local candidate=1
forvalues j=1/`nbitems' {
if "`i'"=="``j''" {
local candidate=0
}
}
if `candidate'==1 {
qui levelsof `i' if `touse'
local r=r(r)
local categorical2 `categorical2' `i'
}
}
local categorical `categorical2'
}
if "`all'"!="" {
*local continuous
*local categorial
foreach i of varlist * {
local candidate=1
forvalues j=1/`nbitems' {
if "`i'"=="``j''" {
local candidate=0
}
}
local type : type `i'
local type=substr("`type'",1,3)
if "`type'"=="str" {
local candidate=0
}
qui levelsof `i' if `touse'
local r=r(r)
if `r'>7&`candidate'==1 {
local continuous `continuous' `i'
}
else {
local categorical `categorical' `i'
}
}
}
*di "CONTINUOUS : `continuous'"
*di "CATEGORICAL : `categorical'"
if "`continuous'"!="" {
di
di "Descriptive analysis of continuous covariates"
local long2=72
di in green "{hline `long2'}"
di in green "Variables" _col(22) "Obs" _col(33) "Mean" _col(40) "Std. Dev." _col(58) "Min" _col(70) "Max"
di in green "{hline `long2'}"
foreach i of varlist `continuous' {
qui su `i' if `touse'
local k=abbrev("`i'",18)
*di in green "`k'" _c
di in green "`k'" _col(20) as result %5.0f `r(N)' _col(30) %7.2f `r(mean)' _col(42) %7.2f `r(sd)' _col(54) %7.2f `r(min)' _col(66) %7.2f `r(max)'
}
di in green "{hline `long2'}"
}
if "`categorical'"!="" {
di
*set trace on
di "Descriptive analysis of categorical covariates"
local long2=55
di in green "{hline `long2'}"
di in green "Variables" _col(25) "Levels" _col(37) "Freq." _col(49) "Percent"
di in green "{hline `long2'}"
local nbc: word count `categorical'
local m=1
local nonret
foreach i of varlist `categorical' {
local type : type `i'
local type=substr("`type'",1,3)
qui levelsof `i'
local lev "`r(levels)'"
local nblev=r(r)
if (`maxlevels'>=`nblev') {
local k=abbrev("`i'",20)
di in green "`k'" _c
if "`type'"=="str" {
foreach j in `lev' {
qui count if `touse'&`i'=="`j'"
local k=abbrev("`j'",10)
di _col(21) %10s in green "`k'" as result %5.0f _col(37) `r(N)' %6.2f _col(49) `=`r(N)'/`N'*100' "%"
}
qui count if `touse'&`i'==""
if `r(N)'!=0 {
di as result %5.0f _col(37) `r(N)' %6.2f _col(49) `=`r(N)'/`N'*100' "%"
}
}
else {
foreach j in `lev' {
qui count if `touse'&`i'==`j'
di _col(21) %10s in green "`j'" as result %5.0f _col(37) `r(N)' %6.2f _col(49) `=`r(N)'/`N'*100' "%"
}
qui count if `touse'&`i'==.
if `r(N)'!=0 {
di as result %5.0f _col(37) `r(N)' %6.2f _col(49) `=`r(N)'/`N'*100' "%"
}
}
if `m'==`nbc' {
di in green "{hline `long2'}"
}
else {
di in green "{dup `long2':-}"
}
}
else {
local nonret `nonret' `i'
*di "local nonret `nonret' `i'"
*di "non retenu `i'"
if `m'==`nbc' {
di in green "{hline `long2'}"
}
}
local ++m
}
if "`nonret'"!="" {
di in green "Not described variables (too more levels) : " as result "`nonret'"
}
}
end

View File

@ -0,0 +1,279 @@
*! Version 1 11 April 2019
*! Jean-Benoit Hardouin
************************************************************************************************************
* Stata program : descscale
* Description of a scale and covariates
* Release 1 : April 12, 2019
*
*
* Historic :
* Version 1 (April 12, 2019) [Jean-Benoit Hardouin]
*
* Jean-benoit Hardouin, PhD, Assistant Professor
* Team of Methods in Patient Centered Outcomes and Health Research (INSERM U1246-SPHERE)
* University of Nantes - Faculty of Pharmaceutical Sciences
* France
* jean-benoit.hardouin@anaqol.org
*
*
* News about this program :http://www.anaqol.org
*
* Copyright 2019 Jean-Benoit Hardouin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
***********************************************************************************************************
program define descscale , rclass
version 8.2
syntax varlist [if] [in] [,MIN(int 0) CONTinuous(varlist) CATegorical(varlist) All PARTition(numlist) Large MEAN MAXlevels(int 20)]
preserve
marksample touse,novarlist
label variable `touse' "selection"
tokenize `varlist'
local nbitems: word count `varlist'
if "`partition'"=="" {
local partition `nbitems'
}
local nbdim:word count `partition'
forvalues i=1/`nbdim' {
local nbitemsdim`i': word `i' of `partition'
}
qui count if `touse'
local N=r(N)
local maxr=0
forvalues i=1/`nbitems' {
qui levelsof ``i'' if `touse'
local r`i'=r(r)
qui su ``i'' if `touse'
local max`i'=r(max)
local mean`i'=r(mean)
if `r`i''>11&"`large'"=="" {
di in red "The number of answer categories to the items is large (>11). Use the -large- option or correct the list of items."
exit
}
if `r`i''>`maxr' {
local maxr `r`i''
}
}
*di "maxr=`maxr'"
di
di in green "Number of individuals : " as result `N'
di
di in green "Decription of the items"
local long=(`maxr'+1-`min')*8+40
di in green "{hline `long'}"
di in green "Items" _col(23) "Obs" _c
local col=33
forvalues j=`min'/`maxr' {
di _col(`col') "`j'" _c
local col=`col'+8
}
di _col(`col') "." _col(`=`col'+4') "Mean"
di in green "{hline `long'}"
local deb=1
forvalues d=1/`nbdim' {
local loi`d'
*di "local fin=`deb'+`nbitemsdim`d''-1"
local fin=`deb'+`nbitemsdim`d''-1
forvalues i=`deb'/`fin' {
local loi`d' `loi`d'' ``i''
qui count if `touse'&``i''!=.
local k=abbrev("``i''",20)
di in green "`k'" _c
di in green "`k'" _col(22) as result %4.0f `r(N)' _c
local col=28
forvalues j=`min'/`maxr' {
qui count if `touse'&``i''==`j'
local per=round(`r(N)'/`N'*100, 0.1)
di _col(`col') %5.1f `per' "%" _c
local col=`col'+8
}
qui count if `touse'&``i''==.
local per=round(`r(N)'/`N'*100,0.1)
di _col(`col') %5.1f `per' "%" _col(`=`col'+9') %4.2f `mean`i''
}
if `d'!=`nbdim' {
di in green "{dup `long':-}"
}
local deb=`fin'+1
}
di in green "{hline `long'}"
di
di in green "Decription of the scores"
local long2=72
di in green "{hline `long2'}"
di in green "Scores" _col(22) "Obs" _col(33) "Mean" _col(40) "Std. Dev." _col(58) "Min" _col(70) "Max"
di in green "{hline `long2'}"
forvalues d=1/`nbdim' {
tempname score`d'
genscore `loi`d'' if `touse', score(`score`d'') `mean' `standardized'
qui su `score`d'' if `touse'
di in green "score`d'" _col(20) as result %5.0f `r(N)' _col(30) %7.2f `r(mean)' _col(42) %7.2f `r(sd)' _col(54) %7.2f `r(min)' _col(66) %7.2f `r(max)'
}
di in green "{hline `long2'}"
if "`continuous'"!=""|"`categorical'"!="" {
local continuous2
foreach i of varlist `continuous' {
local candidate=1
forvalues j=1/`nbitems' {
if "`i'"=="``j''" {
local candidate=0
}
}
local type : type `i'
local type=substr("`type'",1,3)
if "`type'"=="str" {
local candidate=0
}
if `candidate'==1 {
qui levelsof `i' if `touse'
local r=r(r)
local continuous2 `continuous2' `i'
}
}
local continuous `continuous2'
local categorical2
foreach i of varlist `categorical' {
local candidate=1
forvalues j=1/`nbitems' {
if "`i'"=="``j''" {
local candidate=0
}
}
if `candidate'==1 {
qui levelsof `i' if `touse'
local r=r(r)
local categorical2 `categorical2' `i'
}
}
local categorical `categorical2'
}
if "`all'"!="" {
*local continuous
*local categorial
foreach i of varlist * {
local candidate=1
forvalues j=1/`nbitems' {
if "`i'"=="``j''" {
local candidate=0
}
}
local type : type `i'
local type=substr("`type'",1,3)
if "`type'"=="str" {
local candidate=0
}
qui levelsof `i' if `touse'
local r=r(r)
if `r'>7&`candidate'==1 {
local continuous `continuous' `i'
}
else {
local categorical `categorical' `i'
}
}
}
*di "CONTINUOUS : `continuous'"
*di "CATEGORICAL : `categorical'"
if "`continuous'"!="" {
di
di "Descriptive analysis of continuous covariates"
local long2=72
di in green "{hline `long2'}"
di in green "Variables" _col(22) "Obs" _col(33) "Mean" _col(40) "Std. Dev." _col(58) "Min" _col(70) "Max"
di in green "{hline `long2'}"
foreach i of varlist `continuous' {
qui su `i' if `touse'
local k=abbrev("`i'",18)
*di in green "`k'" _c
di in green "`k'" _col(20) as result %5.0f `r(N)' _col(30) %7.2f `r(mean)' _col(42) %7.2f `r(sd)' _col(54) %7.2f `r(min)' _col(66) %7.2f `r(max)'
}
di in green "{hline `long2'}"
}
if "`categorical'"!="" {
di
*set trace on
di "Descriptive analysis of continuous covariates"
local long2=55
di in green "{hline `long2'}"
di in green "Variables" _col(25) "Levels" _col(37) "Freq." _col(49) "Percent"
di in green "{hline `long2'}"
local nbc: word count `categorical'
local m=1
local nonret
foreach i of varlist `categorical' {
local type : type `i'
local type=substr("`type'",1,3)
qui levelsof `i'
local lev "`r(levels)'"
local nblev=r(r)
if (`maxlevels'>=`nblev') {
local k=abbrev("`i'",20)
di in green "`k'" _c
if "`type'"=="str" {
foreach j in `lev' {
qui count if `touse'&`i'=="`j'"
local k=abbrev("`j'",10)
di _col(21) %10s in green "`k'" as result %5.0f _col(37) `r(N)' %6.2f _col(49) `=`r(N)'/`N'*100' "%"
}
qui count if `touse'&`i'==""
if `r(N)'!=0 {
di as result %5.0f _col(37) `r(N)' %6.2f _col(49) `=`r(N)'/`N'*100' "%"
}
}
else {
foreach j in `lev' {
qui count if `touse'&`i'==`j'
di _col(21) %10s in green "`j'" as result %5.0f _col(37) `r(N)' %6.2f _col(49) `=`r(N)'/`N'*100' "%"
}
qui count if `touse'&`i'==.
if `r(N)'!=0 {
di as result %5.0f _col(37) `r(N)' %6.2f _col(49) `=`r(N)'/`N'*100' "%"
}
}
if `m'==`nbc' {
di in green "{hline `long2'}"
}
else {
di in green "{dup `long2':-}"
}
}
else {
local nonret `nonret' `i'
*di "local nonret `nonret' `i'"
*di "non retenu `i'"
if `m'==`nbc' {
di in green "{hline `long2'}"
}
}
local ++m
}
if "`nonret'"!="" {
di in green "Not described variables (too more levels) : " as result "`nonret'"
}
}
end

View File

@ -0,0 +1,302 @@
************************************************************************************************************
* DETECT: detect, Iss and R indexes
* Version 3.1: May 13, 2004
*
* Historic
* Version 1 (2003-06-20): Jean-Benoit Hardouin
* Version 2 (2004-01-18): Jean-Benoit Hardouin
* Version 3 (2004-01-26): Jean-Benoit Hardouin
* Version 3.1 (2004-05-13): Jean-Benoit Hardouin
* Version 4 (2009-11-24): Jean-Benoit Hardouin /*corrections*/
*
* Jean-benoit Hardouin, Regional Health Observatory of Orl<72>ans - France
* jean-benoit.hardouin@neuf.fr
*
* News about this program : http://anaqol.free.fr
* FreeIRT Project : http://freeirt.free.fr
*
* Copyright 2003, 2004 Jean-Benoit Hardouin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
************************************************************************************************************
program define detect , rclass
version 7.0
syntax varlist(min=2 numeric), PARTition(numlist integer >0) [noSCOres noRESTscores]
local nbitemstest=0
tokenize `partition'
local Q:word count `partition'
local firstitem=0
local dim0=1
forvalues i=1/`Q' {
local dim`i'=``i''
local firstitem`i'=`firstitem`=`i'-1''+`dim`=`i'-1''
local nbitemstest=`nbitemstest'+`dim`i''
tempvar score`i'
qui gen `score`i''=0
forvalues j=`firstitem`i''/`=`firstitem`i''+`dim`i''-1' {
local item`j': word `j' of `varlist'
qui replace `score`i''=`score`i''+`item`j''
}
}
local nbitems:word count `varlist'
tokenize `varlist'
if `nbitems'!=`nbitemstest' {
di in red "The sum of the numbers of items in all the dimensions is different of the total number of items precised in varlist"
exit
}
tempname Corrscores Corrrestscores
matrix define `Corrscores'=J(`nbitems',`Q',0)
matrix define `Corrrestscores'=J(`nbitems',`Q',0)
forvalues i=1/`nbitems' {
forvalues j=1/`Q' {
tempvar restscore`i's`j'
qui gen `restscore`i's`j''=`score`j''-``i''
qui corr ``i'' `score`j''
local corr`i's`j'=r(rho)
qui corr ``i'' `restscore`i's`j''
local corr`i'rs`j'=r(rho)
matrix `Corrscores'[`i',`j']=`corr`i's`j''
matrix `Corrrestscores'[`i',`j']=`corr`i'rs`j''
}
}
qui count
local nbind=r(N)
tempvar score
qui gen `score'=0
forvalues i=1/`nbitems' {
qui replace `score'=`score'+``i''
}
forvalues i=1/`nbitems' {
local tmp=`i'+1
forvalues j=`tmp'/`nbitems' {
tempvar restscorei`i'j`j'
qui gen `restscorei`i'j`j''=`score'-``i''-``j''
}
}
forvalues k=0/`nbitems'{
tempname Tcov`k'
qui count if `score'==`k'
local n`k'=r(N)
if `n`k''>1 {
qui matrix accum `Tcov`k''=`varlist' if `score'==`k',nocons dev
}
else {
matrix `Tcov`k''=J(`nbitems',`nbitems',0)
}
if `n`k''!=0 {
matrix `Tcov`k''=`Tcov`k''/`n`k''
}
}
forvalues i=1/`nbitems'{
local tmp=`i'+1
forvalues j=`tmp'/`nbitems' {
local tmp=`nbitems'-2
forvalues k=0/`tmp' {
tempname Rcovi`i'j`j'k`k'
qui count if `restscorei`i'j`j''==`k'
local ni`i'j`j'k`k'=r(N)
if `ni`i'j`j'k`k''>1 {
qui matrix accum `Rcovi`i'j`j'k`k''=`varlist' if `restscorei`i'j`j''==`k',nocons dev
}
else {
matrix `Rcovi`i'j`j'k`k''=J(`nbitems',`nbitems',0)
}
if `ni`i'j`j'k`k''!=0 {
matrix `Rcovi`i'j`j'k`k''=`Rcovi`i'j`j'k`k''/`ni`i'j`j'k`k''
}
}
}
}
tempname delta
matrix `delta'=J(`nbitems',`nbitems',-1)
local debut=1
local fin=0
forvalues i=1/`Q' {
local fin=`fin'+`dim`i''
forvalues j=`debut'/`fin' {
forvalues k=`debut'/`fin' {
matrix `delta'[`j',`k']=1
}
}
local debut=`debut'+`dim`i''
}
tempname Tcov Rcov Covfin Issm Abscov
matrix `Tcov'=J(`nbitems',`nbitems',0)
matrix `Rcov'=J(`nbitems',`nbitems',0)
forvalues k=0/`nbitems' {
matrix `Tcov'=`Tcov'+`Tcov`k''*`n`k''
}
forvalues i=1/`nbitems'{
local tmp=`i'+1
forvalues j=`tmp'/`nbitems' {
local tmp=`nbitems'-2
forvalues k=0/`tmp' {
matrix `Rcov'[`i',`j']=`Rcov'[`i',`j']+`Rcovi`i'j`j'k`k''[`i',`j']*`ni`i'j`j'k`k''
matrix `Rcov'[`j',`i']=`Rcov'[`i',`j']
}
}
}
matrix `Covfin'=J(`nbitems',`nbitems',0)
matrix `Issm'=J(`nbitems',`nbitems',0)
matrix `Abscov'=J(`nbitems',`nbitems',0)
forvalues i=1/`nbitems' {
forvalues j=1/`nbitems' {
matrix `Covfin'[`i',`j']=(`Tcov'[`i',`j']+`Rcov'[`i',`j'])/2*`delta'[`i',`j']
matrix `Issm'[`i',`j']=sign(`Tcov'[`i',`j']+`Rcov'[`i',`j'])*`delta'[`i',`j']
matrix `Abscov'[`i',`j']=abs(`Tcov'[`i',`j']+`Rcov'[`i',`j'])/2
}
}
local somme=0
local Iss=0
local R=0
forvalues i=1/`nbitems' {
local tmp=`i'+1
forvalues j=`tmp'/`nbitems' {
local somme=`somme'+`Covfin'[`i',`j']
local Iss=`Iss'+`Issm'[`i',`j']
local R=`R'+`Abscov'[`i',`j']
}
}
local DETECT=`somme'/(`nbind'*`nbitems'*(`nbitems'-1))
local DETECT=`somme'/(`nbitems'*(`nbitems'-1))
local Iss=`Iss'*2/(`nbitems'*(`nbitems'-1))
*local R=`DETECT'/(`R'/(`nbind'*`nbitems'*(`nbitems'-1)))
local R=`DETECT'/(`R'/(`nbitems'*(`nbitems'-1)))
di
di in green _col(20) "DETECT : " as result %5.4f `DETECT'
di in green _col(23) "Iss : " as result %5.4f `Iss'
di in green _col(25) "R : " as result %5.4f `R'
di
if "`scores'"=="" {
di _col(5) in green "Correlations Items-Scores"
di in green _col(5) "{hline 25}"
di
di in green _col(5) "Items" _continue
local col=10
forvalues q=1/`Q' {
local col=`col'+10
di in green _col(`col') "dim `q'" _continue
}
di
local length=`Q'*10+10
di in green _col(5) "{hline `length'}"
forvalues i=1/`nbitems' {
forvalues q=2/`Q' {
if `i'==`firstitem`q'' {
di _col(5) in green _dup(`length') "-"
}
}
di in green _col(5) "``i''" _continue
local col=5
forvalues q=1/`Q' {
local col=`col'+10
di in yellow _col(`col') %10.4f `corr`i's`q'' _continue
}
di
}
di in green _col(5) "{hline `length'}"
di
}
if "`restscore'"=="" {
di _col(5) in green "Correlations Items-Rest-Scores"
di in green _col(5) "{hline 30}"
di
di in green _col(5) "Items" _continue
local col=10
forvalues q=1/`Q' {
local col=`col'+10
di in green _col(`col') "dim `q'" _continue
}
di
local length=`Q'*10+10
di in green _col(5) "{hline `length'}"
forvalues i=1/`nbitems' {
forvalues q=2/`Q' {
if `i'==`firstitem`q'' {
di _col(5) in green _dup(`length') "-"
}
}
di in green _col(5) "``i''" _continue
local col=5
forvalues q=1/`Q' {
local col=`col'+10
di in yellow _col(`col') %10.4f `corr`i'rs`q'' _continue
}
di
}
di in green _col(5) "{hline `length'}"
di
}
local namesdim
forvalues q=1/`Q' {
local namesdim "`namesdim' dim`q'"
}
matrix rownames `Tcov'=`varlist'
matrix rownames `Rcov'= `varlist'
matrix rownames `Covfin'= `varlist'
matrix rownames `Corrscores'= `varlist'
matrix rownames `Corrrestscores'= `varlist'
matrix colnames `Tcov'= `varlist'
matrix colnames `Rcov' =`varlist'
matrix colnames `Covfin'= `varlist'
matrix colnames `Corrscores'= `namesdim'
matrix colnames `Corrrestscores'= `namesdim'
return scalar DETECT=`DETECT'
return scalar Iss=`Iss'
return scalar R=`R'
return matrix Tcov `Tcov'
return matrix Rcov `Rcov'
return matrix Covfin `Covfin'
return matrix Corrscores `Corrscores'
return matrix Corrrestscores `Corrrestscores'
end

View File

@ -0,0 +1,48 @@
{smcl}
{* 26jan2004}{...}
{hline}
help for {hi:detect}
{hline}
{title:DETECT Index}
{p 8 14 2}{cmd:detect} {it:varlist} {cmd:,} {cmdab:part:ition}({it:numlist}) [{cmdab:nosco:res} {cmdab:norest:scores}]
{p 4 4 2}{it:varlist} is a list of two existing dichotomous variables (items) or more. The first items of this list compose the first dimension, the following items define the second dimension, as so on.
{p 4 4 2}{cmd:partition} permit to define the number of items in each dimension. The user must precise in the {it:numlist} the number of items in each dimension.
{Options}
{p 4 4 2}{cmd:noscores} permit to remove the table of the correlations between the items and the scores
{p 4 4 2}{cmd:norestscores} permit to remove the table of the correlations between the items and the rest-scores
{title:Description}
{p 4 4 2}{cmd:detect} permit to compute the DETECT index (Dimensionality Evaluation to Enumerate Contributing Traits), as the Iss (Approximate Simple Structure Index) and the R indexes defined by Zhang and Stout (1999).
{title:Remarks}
{p 4 4 2}For detailed information on the DETECT, Iss and R indexes, see Zhang and Stout (1999).
{p 4 4 2}{cmd:detect} don't permit the use of polytomous items.
{title:Example}
{cmd:. detect item1 item2 item3 item4 , partition(2 2) nosco norest}
{cmd:. detect item1 item2 item3 item4 item 5 item6 item7 , partition(3 2 2)}
{title:References}
{p 4 4 2}Zhang J. and Stout W., The theorical DETECT index of dimensionality and its application to approximate simple structure, {it: Psychometrika}, vol.64(2), 1999, pp. 213-249.
{title:Author}
{p 4 8 2}Jean-Benoit Hardouin, Regional Health Observatory (ORS) - 1, rue Porte Madeleine - BP 2439 - 45032 Orleans Cedex 1 - France.
You can contact the author at {browse "mailto:jean-benoit.hardouin@neuf.fr":jean-benoit.hardouin@neuf.fr} and visit the websites {browse "http://anaqol.free.fr":AnaQol} and {browse "http://freeirt.free.fr":FreeIRT}

View File

@ -0,0 +1,68 @@
************************************************************************************************************
* based on the command "detect" by Jean-Benoit Hardouin
************************************************************************************************************
program define detect2 , rclass
version 7.0
syntax varlist(min=2 numeric), PARTition(numlist integer >0) [noSCOres noRESTscores]
local nbitemstest=0
tokenize `partition'
local Q:word count `partition'
local firstitem=0
local dim0=1
forvalues i=1/`Q' {
local dim`i'=``i''
local firstitem`i'=`firstitem`=`i'-1''+`dim`=`i'-1''
local nbitemstest=`nbitemstest'+`dim`i''
tempvar score`i'
qui gen `score`i''=0
forvalues j=`firstitem`i''/`=`firstitem`i''+`dim`i''-1' {
local item`j': word `j' of `varlist'
qui replace `score`i''=`score`i''+`item`j''
}
}
local nbitems:word count `varlist'
tokenize `varlist'
if `nbitems'!=`nbitemstest' {
di in red "The sum of the numbers of items in all the dimensions is different of the total number of items precised in varlist"
exit
}
tempname Corrscores Corrrestscores
matrix define `Corrscores'=J(`nbitems',`Q',0)
matrix define `Corrrestscores'=J(`nbitems',`Q',0)
forvalues i=1/`nbitems' {
forvalues j=1/`Q' {
tempvar restscore`i's`j'
qui gen `restscore`i's`j''=`score`j''-``i''
qui corr ``i'' `score`j''
local corr`i's`j'=r(rho)
qui corr ``i'' `restscore`i's`j''
local corr`i'rs`j'=r(rho)
matrix `Corrscores'[`i',`j']=`corr`i's`j''
matrix `Corrrestscores'[`i',`j']=`corr`i'rs`j''
}
}
local namesdim
forvalues q=1/`Q' {
local namesdim "`namesdim' dim`q'"
}
matrix colnames `Corrscores'= `namesdim'
matrix colnames `Corrrestscores'= `namesdim'
return matrix Corrscores `Corrscores'
return matrix Corrrestscores `Corrrestscores'
end

View File

@ -0,0 +1,23 @@
program define dropmissing
syntax varlist [, missing(string) delete]
tokenize `varlist'
local nbitems:word count `varlist'
if "`missing'"=="" {
local missing="."
}
local nbmissing:word count `missing'
forvalues i=1/`nbitems' {
forvalues j=1/`nbmissing' {
local miss:word `j' of `missing'
if "`delete'"!="" {
drop if ``i''==`miss'
}
else {
replace ``i'=. if ``i''==`miss'
}
}
}
end