Computed theoretical power for N=100 and N=200 scenarios
This commit is contained in:
645
Modules/ado/personal/t/tcm.ado
Normal file
645
Modules/ado/personal/t/tcm.ado
Normal file
@ -0,0 +1,645 @@
|
||||
* Tcm : Estimation pour une entit<69> g<>ographique donn<6E>e de la r<>gion centre des taux de mortalitr<74> par age
|
||||
* quinquennal, et du TCM, avec possibilit<69> de comparer ce dernier <20> une valeur th<74>orique
|
||||
*
|
||||
* Version 2.6 : 21 janvier 2005 (corrections pour le calcul test du TCM <20> une valeur de r<>f<EFBFBD>rence)
|
||||
* Version 2.5 : 13 janvier 2005 (corrections pour le calcul du nb de d<>c<EFBFBD>s observ<72>s avec ICMPART)
|
||||
* Version 2.4 : 11 janvier 2005 (quelques am<61>liorations par rapport <20> la version 2.3)
|
||||
* Version 2.3 : 6 janvier 2005 (options ICM et ICMPART, age maximal par defaut <20> 95)
|
||||
* Version 2.2 : 16 d<>cembre 2004
|
||||
* Version 2.1 : 7 d<>cembre 2004
|
||||
* Version 2 : 22 octobre 2004
|
||||
* Version 1.4 : 2 septembre 2004
|
||||
* Version 1.3: 16 aout 2004
|
||||
* Version 1.2: 22 juillet 2004
|
||||
* Version 1.1: 16 juillet 2004
|
||||
* Version 1: 16 juillet 2004
|
||||
*
|
||||
* Jean-benoit Hardouin, Observatoire R<>gional de la Sant<6E> du Centre - Orl<72>ans - France
|
||||
* jean-benoit.hardouin@orscentre.fr
|
||||
*
|
||||
* Copyright 2004-2005 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 tcm,rclass
|
||||
version 7.0
|
||||
syntax [, s10(numlist) agemax(int 95) sexe(int 0) sexestd(int 0) anneepop(int 1999) anneepopstd(int 1999) annees(numlist) anneesstd(numlist) codegeo(int 1) codegeostd(int 0) prema(int 65) details tcmcomp(real 0) icm icmpart(numlist)]
|
||||
|
||||
|
||||
/*********************************************************************************************
|
||||
TESTS PRELIMINAIRES
|
||||
*********************************************************************************************/
|
||||
|
||||
if `sexe'<0|`sexe'>2 {
|
||||
di in red "Vous devez indiquer un sexe parmi 0 (deux sexes confondus), 1 (hommes) ou 2 (femmes)"
|
||||
exit
|
||||
}
|
||||
if `sexestd'<0|`sexestd'>2 {
|
||||
di in red "Vous devez indiquer un sexe de reference parmi 0 (deux sexes confondus), 1 (hommes) ou 2 (femmes)"
|
||||
exit
|
||||
}
|
||||
if `anneepop'<82|(`anneepop'>99&`anneepop'<1982)|`anneepop'>1999 {
|
||||
di in red "Vous devez indiquer une annee de reference entre 1982 et 1999 [82 et 99] (compris)"
|
||||
exit
|
||||
}
|
||||
if `codegeo'==0 {
|
||||
di in red "Il n'est pas encore possible de travailler sur la France entiere, mais cela viendra bien assez tot"
|
||||
exit
|
||||
}
|
||||
|
||||
local st = "$S_TIME"
|
||||
|
||||
|
||||
/*********************************************************************************************
|
||||
SI UNE BASE EST OUVERTE, ON LA SAUVEGARDE
|
||||
*********************************************************************************************/
|
||||
|
||||
capture su *
|
||||
if _rc==0 {
|
||||
tempfile tmp
|
||||
if "`details'"!="" {
|
||||
di in green "** Sauvegarde en cours"
|
||||
}
|
||||
qui save `tmp',replace
|
||||
}
|
||||
preserve
|
||||
|
||||
/*********************************************************************************************
|
||||
PAR DEFAUT
|
||||
*********************************************************************************************/
|
||||
|
||||
|
||||
if "`s10'"=="" {
|
||||
local s10des Toutes les causes
|
||||
local s10 101(1)105 201(1)231 301 302 401 501 502 601 602 701(1)707 801(1)806 901(1)903 1001 1101 1201 1301 1401 1501 1600(1)1603 1701(1)1709
|
||||
}
|
||||
else {local s10des `s10'}
|
||||
|
||||
if "`annees'"=="" {
|
||||
local annees 1998(1)2000
|
||||
}
|
||||
local anneesdes `annees'
|
||||
|
||||
if "`anneesstd'"=="" {
|
||||
local anneesstd `annees'
|
||||
}
|
||||
local anneesdesstd `anneesstd'
|
||||
|
||||
/*********************************************************************************************
|
||||
VERIFICATION ICM
|
||||
Pour calculer un ICM, il faut que le sexe, la p<>riode et la population de r<>f<EFBFBD>rence
|
||||
*********************************************************************************************/
|
||||
|
||||
if `sexestd'!=`sexe'&"`icm'"!="" {
|
||||
di in yellow "Le sexe de la population de reference (option sexestd) a ete modifie pour etre identique a celui de la population de travail (option sexe) et a desormais pour valeur `sexe'"
|
||||
local sexestd=`sexe'
|
||||
}
|
||||
if "`anneesstd'"!="`annees'"&"`icm'"!="" {
|
||||
di in yellow "La periode utilisee pour la population de reference (option anneesstd) a ete modifiee pour etre identique a celle utilisee pour la population de travail (option annees) et a desormais pour valeur `annees'"
|
||||
local anneesstd `annees'
|
||||
}
|
||||
if "`anneepopstd'"!="`anneepop'"&"`icm'"!="" {
|
||||
di in yellow "La population de reference (option anneepopstd) a ete modifiee pour etre identique a la population de travail (option anneepop) et a desormais pour valeur `anneepop'"
|
||||
local anneepopstd `anneepop'
|
||||
}
|
||||
if "`icm'"==""&"`annees'"=="`anneesstd'"&`sexe'==`sexestd' {
|
||||
di in yellow "Les options indiquees semblent etre correctes pour calculer un ICM"
|
||||
local icm icm
|
||||
}
|
||||
else if "`icm'"==""{
|
||||
di in yellow "Les options indiquees ne semblent pas etre correctes pour calculer un ICM : Attention en utilisant celui-ci"
|
||||
}
|
||||
|
||||
/*********************************************************************************************
|
||||
SI LA STANDARDISATION SE FAIT SUR LA FRANCE
|
||||
*********************************************************************************************/
|
||||
|
||||
|
||||
if `codegeostd'==0 {
|
||||
use "C:\ado\personal\files\dcfrance8000long.dta", clear
|
||||
qui gen flagstd=0
|
||||
foreach i of numlist `anneesstd' {
|
||||
qui replace flagstd=1 if annee==`i'
|
||||
}
|
||||
qui keep if flagstd==1
|
||||
|
||||
qui replace flagstd=0
|
||||
foreach i of numlist `s10' {
|
||||
qui replace flagstd=1 if s10==`i'
|
||||
}
|
||||
qui keep if flagstd==1
|
||||
|
||||
qui replace flagstd=0
|
||||
if `sexestd'!=0 {
|
||||
qui replace flagstd=1 if sexe==`sexestd'
|
||||
qui keep if flagstd==1
|
||||
}
|
||||
|
||||
qui gen n=1
|
||||
foreach i of numlist 0 1 5(5)`=`agemax'-5' {
|
||||
qui su n if age==`i' [weight=eff]
|
||||
local Nstd`i'=r(sum)
|
||||
}
|
||||
qui su n if age>=`agemax' [weight=eff]
|
||||
local Nstd`agemax'=r(sum)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************************************************
|
||||
ON OUVRE LA BASE DE MORTALITE
|
||||
*********************************************************************************************/
|
||||
|
||||
if "`details'"!="" {
|
||||
di in green "** Ouverture de la base"
|
||||
}
|
||||
use "C:\ado\personal\files\dccentre8000reduit.dta",replace
|
||||
|
||||
if "`details'"!="" {
|
||||
di in green "** Base ouverte"
|
||||
}
|
||||
|
||||
/*********************************************************************************************
|
||||
ON SELECTIONNE LES INFORMATIONS
|
||||
*********************************************************************************************/
|
||||
|
||||
|
||||
if "`details'"!="" {
|
||||
di in green "** Selection de l'information necessaire"
|
||||
}
|
||||
|
||||
|
||||
|
||||
numlist "`annees'"
|
||||
local nbans:word count `r(numlist)'
|
||||
local mod=mod(`nbans',2)
|
||||
if `mod'==0 {
|
||||
local juillet=""
|
||||
}
|
||||
else if `mod'==1 {
|
||||
local juillet="juillet"
|
||||
}
|
||||
if `codegeo'<100&"`juillet'"=="" {
|
||||
local commpoptr="Estimation INSEE au 1er janvier"
|
||||
}
|
||||
else if `codegeo'<100&"`juillet'"!="" {
|
||||
local commpoptr="Estimation INSEE au 1er juillet"
|
||||
}
|
||||
else if `codegeo'>100 {
|
||||
local commpoptr="R<>tropolation entre les recencements pour"
|
||||
}
|
||||
|
||||
numlist "`anneesstd'"
|
||||
local nbansstd:word count `r(numlist)'
|
||||
local mods=mod(`nbansstd',2)
|
||||
if `mods'==0 {
|
||||
local juilletstd=""
|
||||
}
|
||||
else if `mods'==1 {
|
||||
local juilletstd="juillet"
|
||||
}
|
||||
if `codegeostd'<100&"`juilletstd'"=="" {
|
||||
local commpopstd="Estimation INSEE au 1er janvier"
|
||||
}
|
||||
else if `codegeostd'<100&"`juilletstd'"!="" {
|
||||
local commpopstd="Estimation INSEE au 1er juillet"
|
||||
}
|
||||
else if `codegeostd'>100 {
|
||||
local commpopstd="R<>tropolation entre les recencements pour"
|
||||
}
|
||||
|
||||
|
||||
tempvar keeps10 keepsexe keepannees keepgeo
|
||||
gen `keeps10'=0
|
||||
gen `keepsexe'=0
|
||||
gen `keepannees'=0
|
||||
gen `keepgeo'=0
|
||||
|
||||
if "`details'"!="" {
|
||||
di in green "** Selection en fonction du sexe"
|
||||
}
|
||||
|
||||
if `sexe'==0 {
|
||||
qui replace `keepsexe'=1
|
||||
}
|
||||
else {
|
||||
qui replace `keepsexe'=1 if sexe==`sexe'
|
||||
}
|
||||
|
||||
qui keep if `keepsexe'==1
|
||||
|
||||
|
||||
if "`details'"!="" {
|
||||
di in green "** Selection des annees"
|
||||
}
|
||||
|
||||
foreach i of numlist `annees' {
|
||||
qui replace `keepannees'=1 if annee==`i'
|
||||
}
|
||||
|
||||
qui keep if `keepannees'==1
|
||||
|
||||
if "`details'"!="" {
|
||||
di in green "** Selection de la zone geographique"
|
||||
}
|
||||
|
||||
if `codegeo'==1 {
|
||||
qui replace `keepgeo'=1
|
||||
}
|
||||
|
||||
if `codegeo'>10&`codegeo'<100 {
|
||||
qui replace `keepgeo'=1 if deptdom==`codegeo'
|
||||
}
|
||||
|
||||
if `codegeo'>1000&`codegeo'<10000&int(`codegeo'/100)!=24 {
|
||||
qui replace `keepgeo'=1 if codepct==`codegeo'
|
||||
}
|
||||
|
||||
if int(`codegeo'/100)==24 {
|
||||
qui replace `keepgeo'=1 if ze94==`codegeo'
|
||||
}
|
||||
|
||||
if `codegeo'>10000&`codegeo'<100000 {
|
||||
qui replace `keepgeo'=1 if comdom==`codegeo'
|
||||
}
|
||||
|
||||
qui keep if `keepgeo'==1
|
||||
|
||||
|
||||
if "`details'"!="" {
|
||||
di in green "** Selection des codes S10"
|
||||
}
|
||||
|
||||
foreach i of numlist `s10' {
|
||||
qui replace `keeps10'=1 if S10==`i'
|
||||
}
|
||||
|
||||
qui keep if `keeps10'==1
|
||||
|
||||
|
||||
if "`details'"!="" {
|
||||
di in green "** Selection finale"
|
||||
}
|
||||
|
||||
qui keep if `keeps10'==1&`keepsexe'==1&`keepannees'==1&`keepgeo'==1
|
||||
|
||||
if "`details'"!="" {
|
||||
di in green "** Selection terminee"
|
||||
}
|
||||
|
||||
/*********************************************************************************************
|
||||
ON CHERCHE LES INTITULES DE ZONE, DE SEXE POUR LA POPULATION DE TRAVAIL
|
||||
*********************************************************************************************/
|
||||
|
||||
qui count
|
||||
local N=r(N)
|
||||
qui count if age!=0
|
||||
local N0=r(N)
|
||||
if `codegeo'==1 {local zone region Centre}
|
||||
else if `codegeo'==18 {local zone Cher}
|
||||
else if `codegeo'==28 {local zone Eure-et-Loir}
|
||||
else if `codegeo'==36 {local zone Indre}
|
||||
else if `codegeo'==37 {local zone Indre-et-Loire}
|
||||
else if `codegeo'==41 {local zone Loir-et-Cher}
|
||||
else if `codegeo'==45 {local zone Loiret}
|
||||
else {
|
||||
qui trouve `codegeo'
|
||||
local zone `r(trouve`codegeo')'
|
||||
if "`zone'"=="" {
|
||||
local zone Non reconnue
|
||||
}
|
||||
}
|
||||
|
||||
if `sexe'==0 {local sexedes Deux sexes}
|
||||
else if `sexe'==1 {local sexedes Hommes}
|
||||
else if `sexe'==2 {local sexedes Femmes}
|
||||
else {local sexedes Non reconnu}
|
||||
|
||||
/*********************************************************************************************
|
||||
ON CHERCHE LES INTITULES DE ZONE, DE SEXE POUR LA POPULATION DE STANDARDISATION
|
||||
*********************************************************************************************/
|
||||
|
||||
|
||||
if `sexestd'==0 {local sexerefdes Deux sexes}
|
||||
else if `sexestd'==1 {local sexerefdes Hommes}
|
||||
else if `sexestd'==2 {local sexerefdes Femmes}
|
||||
else {local sexerefdes Non reconnu}
|
||||
|
||||
|
||||
if `codegeostd'==0 {local zonestd France metropolitaine}
|
||||
else if `codegeostd'==1 {local zonestd region Centre}
|
||||
else if `codegeostd'==18 {local zonestd Cher}
|
||||
else if `codegeostd'==28 {local zonestd Eure-et-Loir}
|
||||
else if `codegeostd'==36 {local zonestd Indre}
|
||||
else if `codegeostd'==37 {local zonestd Indre-et-Loire}
|
||||
else if `codegeostd'==41 {local zonestd Loir-et-Cher}
|
||||
else if `codegeostd'==45 {local zonestd Loiret}
|
||||
else {
|
||||
qui trouve `codegeostd'
|
||||
local zonestd `r(trouve`codegeostd')'
|
||||
if "`zonestd'"=="" {
|
||||
local zonestd Non reconnue
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************************************
|
||||
ENTETE DE SORTIE
|
||||
*********************************************************************************************/
|
||||
|
||||
di in green "- POPULATION DE TRAVAIL -"
|
||||
di in green "Zone geographique : " in yellow "`zone'"
|
||||
di in green "Periode : " in yellow "`anneesdes'" in green " (" in yellow "`nbans' an(s)" in green ")"
|
||||
di in green "Population : " in yellow "`commpoptr' `anneepop'"
|
||||
di in green "Sexe : " in yellow "`sexedes'"
|
||||
di
|
||||
di in green "- POPULATION DE REFERENCE -"
|
||||
di in green "Zone geographique : " in yellow "`zonestd' "
|
||||
di in green "Periode : " in yellow "`anneesdesstd'" in green " (" in yellow "`nbansstd' an(s)" in green ")"
|
||||
di in green "Population : " in yellow "`commpopstd' `anneepopstd'"
|
||||
di in green "Sexe: " in yellow "`sexerefdes'"
|
||||
di
|
||||
di in green "Deces prematures : <" in yellow "`prema'" in green " ans"
|
||||
di in green "S10 : " in yellow "`s10des'"
|
||||
di
|
||||
|
||||
/*********************************************************************************************
|
||||
NB DE DECES ET DE DECES PREMATURES
|
||||
*********************************************************************************************/
|
||||
|
||||
di in green "Nombre de deces concernes : " in yellow `N' _col(55) in green "Nombre de deces concernes >0 an : " in yellow `N0'
|
||||
qui count if age<`prema'
|
||||
local Nprema=r(N)
|
||||
local Pprema=`Nprema'/`N'
|
||||
qui count if age<`prema'&age>0
|
||||
local N0prema=r(N)
|
||||
local P0prema=`N0prema'/`N0'
|
||||
di in green "Nombre de deces prematures : " in yellow `Nprema' in green " (" in yellow %5.1f `=`Pprema'*100' in green "%)" _col(55) in green "Nombre de deces prematures >0 an : " in yellow `N0prema' in green " (" in yellow %5.1f `=`P0prema'*100' in green "%)"
|
||||
|
||||
/*********************************************************************************************
|
||||
TAILLE DE POPULATION DE LA POPULATION DE TRAVAIL
|
||||
*********************************************************************************************/
|
||||
|
||||
tempvar agerec
|
||||
gen `agerec'=age
|
||||
qui recode `agerec' 0=0 `agemax'/105=`agemax'
|
||||
|
||||
local trancheage 0 1 5(5)`agemax'
|
||||
|
||||
qui estpop , annee(`anneepop') codegeo(`codegeo') sexe(`sexe') `juillet'
|
||||
foreach i of numlist 0 1 5(5)`=`agemax'-5' {
|
||||
local popr`i'=r(poprq`i')
|
||||
}
|
||||
local popr`agemax'=0
|
||||
foreach i of numlist `agemax'(5)95 {
|
||||
local popr`agemax'=`popr`agemax''+r(poprq`i')
|
||||
}
|
||||
|
||||
local popr=r(popr)/*-r(popr0)*/
|
||||
|
||||
|
||||
/*********************************************************************************************
|
||||
TAILLE DE POPULATION DE LA POPULATION DE STANDARDISATION
|
||||
*********************************************************************************************/
|
||||
|
||||
|
||||
qui estpop , annee(`anneepopstd') codegeo(`codegeostd') sexe(`sexestd') `juilletstd'
|
||||
foreach i of numlist 0 1 5(5)`=`agemax'-5' {
|
||||
local pop`i'=r(poprq`i')
|
||||
}
|
||||
local pop`agemax'=0
|
||||
foreach i of numlist `agemax'(5)95 {
|
||||
local pop`agemax'=`pop`agemax''+r(poprq`i')
|
||||
}
|
||||
local pop=r(popr)/*-r(popr0) */
|
||||
|
||||
/*********************************************************************************************
|
||||
TABLEAU DE SORTIE
|
||||
*********************************************************************************************/
|
||||
|
||||
di
|
||||
di in green "{hline 14}{c TT}{hline 33}{c TT}{hline 33}{c TT}{hline 20}"
|
||||
di in green _col(15) "{c |}" _col(21) "POPULATION DE TRAVAIL" _col(49) "{c |}" _col(55) "POPULATION DE REFERENCE" _col(83) "{c |}"
|
||||
di in green "{hline 14}{c +}{hline 33}{c +}{hline 33}{c +}{hline 20}"
|
||||
di in green "Tranche" _col(15) "{c |}" _col(16) "Population" _col(29) "Nombre" _col(37) "Taux brut de" _col(49) "{c |}" _col(50) "Population" _col(61) "Nombre de" _col(71) "Taux brut de" _col(83) "{c |}" _col(85) "Nb de deces"
|
||||
di in green "d'age" _col(15) "{c |}" _col(22) "`anneepop'" _col(27) "de deces" _col(39) "mortalite*" _col(49) "{c |}" _col(56) "`anneepopstd'" _col(65) "deces" _col(73) "mortalite*" _col(83) "{c |}" _col(88) "attendus" _col(100) "ICM"
|
||||
di in green "{hline 14}{c +}{hline 33}{c +}{hline 33}{c +}{hline 20}"
|
||||
|
||||
/*********************************************************************************************
|
||||
CALCUL CHEZ LES 0 AN DU TAUX BRUT
|
||||
*********************************************************************************************/
|
||||
|
||||
local tcm=0
|
||||
local vartcm=0
|
||||
local varicm=0
|
||||
local apvp=0
|
||||
|
||||
/*qui count if `agerec'==0
|
||||
local Nage0=r(N)
|
||||
local txbrut0=`Nage0'/`popr0'*100000/`nbans'
|
||||
local txstd0=`Nstd0'/`pop0'*100000/`nbansstd'
|
||||
local NE0=`popr0'*`txstd0'/100000*`nbans'
|
||||
local apvp0=`Nage0'*`prema'
|
||||
di in green "O an" _col(15) "{c |}" _col(18) in yellow %8.0f `popr0' _col(27) %8.0f `Nage0' _col(40) %8.1f `txbrut0' _col(49) in green "{c |}" in yellow _col(52) %8.0f `pop0' _col(62) %8.0f `Nstd0' _col(74) %8.1f `txstd0' _col(83) in green "{c |}" _col(88) in yellow %8.1f `NE0' _col(97) %6.1f `=`Nage0'/`NE0'*100'
|
||||
di in green "{dup 14:-}{c +}{dup 33:-}{c +}{dup 33:-}{c +}{dup 20:-}"
|
||||
*/
|
||||
/*********************************************************************************************
|
||||
CALCUL POUR CHAQUE TRANCHE D'AGE DU TAUX BRUT ET DE LA CONTRIBUTION AU TCM
|
||||
*********************************************************************************************/
|
||||
*set trace on
|
||||
if "`icmpart'"!="" {
|
||||
local icmpartmin:word 1 of `icmpart'
|
||||
local icmpartmax:word 2 of `icmpart'
|
||||
qui count if `agerec'>=`icmpartmin'&`agerec'<=`icmpartmax'
|
||||
local Npart=r(N)
|
||||
}
|
||||
|
||||
local N0std=0
|
||||
local NE=0
|
||||
local NEpart=0
|
||||
foreach i of numlist `trancheage' {
|
||||
qui count if `agerec'==`i'
|
||||
local Nage`i'=r(N)
|
||||
if `i'==0 {
|
||||
local tranche 0 an
|
||||
}
|
||||
else if `i'==1 {
|
||||
local tranche 1-4 ans
|
||||
local apvp1=`Nage`i''*62
|
||||
local apvp=`apvp'+`apvp1'
|
||||
}
|
||||
else if `i'==`agemax' {
|
||||
local tranche `agemax' ans et plus
|
||||
}
|
||||
else {
|
||||
local tranche `i'-`=`i'+4' ans
|
||||
if `i'<65 {
|
||||
local apvp`i'=`Nage`i''*(62.5-`i')
|
||||
local apvp=`apvp'+`apvp`i''
|
||||
}
|
||||
}
|
||||
local N0std=`N0std'+`Nstd`i''
|
||||
local txbrut`i'=`Nage`i''/`popr`i''*100000/`nbans'
|
||||
local txstd`i'=`Nstd`i''/`pop`i''*100000/`nbansstd'
|
||||
local NE`i'=`popr`i''*`txstd`i''/100000*`nbans'
|
||||
local NE=`NE'+`NE`i''
|
||||
if "`icmpart'"!="" {
|
||||
if `icmpartmin'<=`i'&`icmpartmax'>=`i' {
|
||||
local NEpart=`NEpart'+`NE`i''
|
||||
}
|
||||
}
|
||||
local icm`i'=`Nage`i''/`NE`i''*100
|
||||
*local varicm=`varicm'+`icm`i''
|
||||
local tcm=`tcm'+`txbrut`i''*`pop`i''/`pop'
|
||||
local vartcm=`vartcm'+(`pop`i''/`pop')^2*`txbrut`i''/100000/`popr`i''
|
||||
di in green "`tranche'" _col(15) "{c |}" _col(18) in yellow %8.0f `popr`i'' _col(27) %8.0f `Nage`i'' _col(40) %8.1f `txbrut`i'' _col(49) in green "{c |}" in yellow _col(52) %8.0f `pop`i'' _col(62) %8.0f `Nstd`i'' _col(74) %8.1f `txstd`i'' _col(83) in green "{c |}" in yellow _col(88) %8.1f `NE`i'' _col(97) %6.1f `icm`i''
|
||||
}
|
||||
di in green "{hline 14}{c +}{hline 33}{c +}{hline 33}{c +}{hline 20}"
|
||||
|
||||
/*********************************************************************************************
|
||||
TAUX BRUT GLOBAL
|
||||
*********************************************************************************************/
|
||||
|
||||
local txbrut=`N'/`popr'*100000/`nbans'
|
||||
local txbrutstd=`=`N0std'/`pop'*100000/`nbansstd''
|
||||
local icm=`N'/`NE'*100
|
||||
*local A=`varicm'
|
||||
local varicm=`icm'^2/`N'
|
||||
di in green "Total" _col(15) "{c |}" in yellow _col(18) %8.0f `popr' _col(27) %8.0f `N' _col(40) %8.1f `txbrut' _col(49) in green "{c |}" in yellow _col(52) %8.0f `pop' _col(62) %8.0f `N0std' _col(74) %8.1f `=`N0std'/`pop'*100000/`nbansstd'' in green _col(83) "{c |}" in yellow _col(88) %8.1f `NE' _col(97) %6.1f `icm'
|
||||
di in green "{hline 14}{c BT}{hline 33}{c BT}{hline 33}{c BT}{hline 20}"
|
||||
|
||||
di in green "APVP=" _col(18) in yellow %10.1f `apvp'
|
||||
|
||||
/*********************************************************************************************
|
||||
TCM
|
||||
*********************************************************************************************/
|
||||
|
||||
|
||||
local tcmicmoins=(`tcm'/100000-1.96*sqrt(`vartcm'))*100000
|
||||
local tcmicplus=(`tcm'/100000+1.96*sqrt(`vartcm'))*100000
|
||||
local icmicmoins=`icm'*(1-1/(9*`N')-1.96/(3*sqrt(`N')))^3
|
||||
local icmicplus=(`N'+1)/`NE'*(1-1/(9*(`N'+1))+1.96/(3*sqrt(`N'+1)))^3*100
|
||||
|
||||
di in green "TCM" _col(20) in yellow %8.2f `tcm' _col(35) in green "Ecart type" _col(45) in yellow %8.2f `=sqrt(`vartcm')*100000' _col(61) in green "[" in yellow %8.2f `tcmicmoins' in green ";" in yellow %8.2f `tcmicplus' in green "]"
|
||||
di in green "ICM" _col(20) in yellow %8.2f `icm' _col(35) in green "Ecart type" _col(45) in yellow %8.2f `=sqrt(`varicm')' _col(61) in green "[" in yellow %8.2f `icmicmoins' in green ";" in yellow %8.2f `icmicplus' in green "] (methode de Byar)"
|
||||
local Zicm=(abs(`N'-`NE')-.5)/sqrt(`NE')
|
||||
local pvalueicm=1-norm(abs(`Zicm'))
|
||||
di in green "H0: ICM=100" _col(35) "Z=" in yellow %6.4f `Zicm' _col(45) in green "p=" in yellow %6.4f `pvalueicm'
|
||||
|
||||
/*********************************************************************************************
|
||||
ICM PARTIEL
|
||||
*********************************************************************************************/
|
||||
|
||||
if "`icmpart'"!="" {
|
||||
di in green "{dup 103:-}"
|
||||
if `icmpartmax'==`agemax' {
|
||||
local icmpartmaxdis "`icmpartmax' et plus"
|
||||
}
|
||||
else {
|
||||
local icmpartmaxdis=`icmpartmax'+4
|
||||
}
|
||||
di in green "ICM Partiel pour les `icmpartmin'/`icmpartmaxdis'"
|
||||
di in green "Deces observes : " _col(20) in yellow %8.0f `Npart'
|
||||
di in green "Deces attendus : " _col(20) in yellow %8.2f `NEpart'
|
||||
local icmpart=`Npart'/`NEpart'*100
|
||||
local varicmpart=`icmpart'^2/`Npart'
|
||||
local icmparticmoins=`icmpart'*(1-1/(9*`Npart')-1.96/(3*sqrt(`Npart')))^3
|
||||
local icmparticplus=(`Npart'+1)/`NEpart'*(1-1/(9*(`Npart'+1))+1.96/(3*sqrt(`Npart'+1)))^3*100
|
||||
local Zicmpart=(abs(`Npart'-`NEpart')-.5)/sqrt(`NEpart')
|
||||
local pvalueicmpart=1-norm(abs(`Zicmpart'))
|
||||
di in green "ICM (`icmpartmin'/`icmpartmaxdis')" _col(20) in yellow %8.2f `icmpart' _col(35) in green "Ecart type" _col(45) in yellow %8.2f `=sqrt(`varicmpart')' _col(61) in green "[" in yellow %8.2f `icmparticmoins' in green ";" in yellow %8.2f `icmparticplus' in green "] (methode de Byar)"
|
||||
di in green "H0: ICM(`icmpartmin'/`icmpartmaxdis')=100" _col(35) "Z=" in yellow %6.4f `Zicmpart' _col(45) in green "p=" in yellow %6.4f `pvalueicmpart'
|
||||
return scalar ICMpart=`icmpart'
|
||||
return scalar ZICMpart=`Zicmpart'
|
||||
return scalar pvalueICMpart=`pvalueicmpart'
|
||||
}
|
||||
|
||||
|
||||
di in green "{hline 103}"
|
||||
di in green "*: par an pour 100 000 habitants"
|
||||
*set trace on
|
||||
|
||||
|
||||
/*********************************************************************************************
|
||||
COMPARAISON DU TCM (TEST)
|
||||
*********************************************************************************************/
|
||||
|
||||
if `tcmcomp'!=0 {
|
||||
local Z=(`tcm'-`tcmcomp')/100000/(sqrt(`vartcm'))
|
||||
local pvalue=1-norm(abs(`Z'))
|
||||
di
|
||||
di in green "Comparaison du TCM a la valeur theorique (`tcmcomp') : Z= " in yellow %8.4f `Z' in green " p= " in yellow %6.4f `pvalue'
|
||||
return scalar ZTCM=`Z'
|
||||
return scalar pvalueTCM=`pvalue'
|
||||
}
|
||||
|
||||
/*********************************************************************************************
|
||||
SORTIES
|
||||
*********************************************************************************************/
|
||||
|
||||
return scalar N0=`N0'
|
||||
return scalar APVP=`apvp'
|
||||
return scalar Popref=`popr'
|
||||
return scalar TCM=`tcm'
|
||||
return scalar TCMICplus=`tcmicplus'
|
||||
return scalar TCMICmoins=`tcmicmoins'
|
||||
return scalar ICM=`icm'
|
||||
return scalar ICMICmoins=`icmicmoins'
|
||||
return scalar ICMICplus=`icmicplus'
|
||||
return scalar N0prema=`N0prema'
|
||||
return scalar ZICM=`Zicm'
|
||||
return scalar pvalueICM=`pvalueicm'
|
||||
return scalar txbrut=`txbrut'
|
||||
return scalar txbrutstd=`txbrutstd'
|
||||
tempname matsave
|
||||
numlist "0 1 5(5)`agemax'"
|
||||
local j `r(numlist)'
|
||||
local l:word count `j'
|
||||
matrix define `matsave'=J(`l',9,0)
|
||||
forvalues i=1/`l' {
|
||||
local k:word `i' of `j'
|
||||
matrix `matsave'[`i',1]=`k'
|
||||
matrix `matsave'[`i',2]=`Nage`k''
|
||||
matrix `matsave'[`i',3]=`popr`k''
|
||||
matrix `matsave'[`i',4]=`txbrut`k''
|
||||
matrix `matsave'[`i',5]=`pop`k''
|
||||
matrix `matsave'[`i',6]=`Nstd`k''
|
||||
matrix `matsave'[`i',7]=`txstd`k''
|
||||
matrix `matsave'[`i',8]=`NE`k''
|
||||
matrix `matsave'[`i',9]=`icm`k''
|
||||
}
|
||||
matrix colnames `matsave'="classe d'age" "nb deces" "pop" "taux brut" "pop reference" "nb deces reference" "taux brut reference" "deces attendus" "icm"
|
||||
return matrix donnees `matsave'
|
||||
|
||||
/*********************************************************************************************
|
||||
RECUPERATION SI BESOIN DE LA BASE INITIALE
|
||||
*********************************************************************************************/
|
||||
|
||||
restore,not
|
||||
qui drop _all
|
||||
if "`tmp'"!="" {
|
||||
if "`details'"!="" {
|
||||
di
|
||||
di in green "** Restauration"
|
||||
}
|
||||
qui use `tmp'
|
||||
}
|
||||
if "`details'"!="" {
|
||||
capture qui elapse `st'
|
||||
di in green "** Temps d'execution : " in yellow "$S_elap " in green "secondes"
|
||||
}
|
||||
|
||||
end
|
||||
|
142
Modules/ado/personal/t/testclv.ado
Normal file
142
Modules/ado/personal/t/testclv.ado
Normal file
@ -0,0 +1,142 @@
|
||||
program define testclv
|
||||
syntax [,corr(real 0) nosim]
|
||||
|
||||
clear
|
||||
qui set matsize 800
|
||||
qui set memory 128m
|
||||
set more off
|
||||
|
||||
if `corr'==0 {
|
||||
local rho 0.0
|
||||
}
|
||||
else if `corr'==1 {
|
||||
local rho 1.0
|
||||
}
|
||||
else {
|
||||
local rho 0`corr'
|
||||
}
|
||||
|
||||
if "`sim'"=="" {
|
||||
capture use "C:\Documents and Settings\Jean-Benoit\Mes documents\THESE\clv\simul (rho=`rho')\result.dta", clear
|
||||
if _rc==0 {
|
||||
mkmat *,matrix(result)
|
||||
use "C:\Documents and Settings\Jean-Benoit\Mes documents\THESE\clv\simul (rho=`rho')\resultpoly.dta", clear
|
||||
mkmat *,matrix(resultpoly)
|
||||
use "C:\Documents and Settings\Jean-Benoit\Mes documents\THESE\clv\simul (rho=`rho')\result2.dta", clear
|
||||
mkmat *,matrix(result2)
|
||||
use "C:\Documents and Settings\Jean-Benoit\Mes documents\THESE\clv\simul (rho=`rho')\resultpoly2.dta", clear
|
||||
mkmat *,matrix(resultpoly2)
|
||||
|
||||
count if resultpoly21!=0
|
||||
local deb=r(N)+1
|
||||
}
|
||||
else {
|
||||
matrix result=J(100,14,0)
|
||||
matrix resultpoly=J(100,14,0)
|
||||
matrix result2=J(100,14,0)
|
||||
matrix resultpoly2=J(100,14,0)
|
||||
local deb=1
|
||||
}
|
||||
forvalues i=`deb'/100 {
|
||||
di "`i'" _c
|
||||
qui simirt,dim(7 7) cov(1 1 `rho') clear nbobs(500) store(C:\Documents and Settings\Jean-Benoit\Mes documents\THESE\clv\simul (rho=`rho')\data`i') replace
|
||||
di "." _c
|
||||
qui clv i*,nodendro nobiplot
|
||||
di "." _c
|
||||
local group:word 1 of `r(bestthresold)'
|
||||
local group2:word 2 of `r(bestthresold)'
|
||||
qui clv,nodendro nobiplot cons(`group')
|
||||
di "." _c
|
||||
matrix tmp=r(affect)
|
||||
matrix result[`i',1]=tmp
|
||||
di "." _c
|
||||
qui clv,nodendro nobiplot cons(`group2')
|
||||
di "." _c
|
||||
matrix tmp=r(affect)
|
||||
matrix result2[`i',1]=tmp
|
||||
|
||||
di "." _c
|
||||
qui clv i*,nodendro nobiplot method(polychoric)
|
||||
di "." _c
|
||||
local group:word 1 of `r(bestthresold)'
|
||||
local group2:word 2 of `r(bestthresold)'
|
||||
qui clv,nodendro nobiplot cons(`group')
|
||||
di "."
|
||||
matrix tmp=r(affect)
|
||||
matrix resultpoly[`i',1]=tmp
|
||||
di "." _c
|
||||
qui clv,nodendro nobiplot cons(`group2')
|
||||
di "."
|
||||
matrix tmp=r(affect)
|
||||
matrix resultpoly2[`i',1]=tmp
|
||||
|
||||
drop _all
|
||||
svmat result
|
||||
save "C:\Documents and Settings\Jean-Benoit\Mes documents\THESE\clv\simul (rho=`rho')\result",replace
|
||||
|
||||
drop _all
|
||||
svmat resultpoly
|
||||
save "C:\Documents and Settings\Jean-Benoit\Mes documents\THESE\clv\simul (rho=`rho')\resultpoly",replace
|
||||
|
||||
drop _all
|
||||
svmat result2
|
||||
save "C:\Documents and Settings\Jean-Benoit\Mes documents\THESE\clv\simul (rho=`rho')\result2",replace
|
||||
|
||||
drop _all
|
||||
svmat resultpoly2
|
||||
save "C:\Documents and Settings\Jean-Benoit\Mes documents\THESE\clv\simul (rho=`rho')\resultpoly2",replace
|
||||
|
||||
}
|
||||
}
|
||||
foreach file in "result" "result2" "resultpoly" "resultpoly2" "result2nd" "result2nd2" {
|
||||
drop _all
|
||||
di "`file'"
|
||||
use "C:\Documents and Settings\Jean-Benoit\Mes documents\THESE\clv\simul (rho=`rho')\\`file'",clear
|
||||
quietly {
|
||||
forvalues i=1/7 {
|
||||
rename `file'`i' itemA`i'
|
||||
rename `file'`=`i'+7' itemB`i'
|
||||
}
|
||||
gen conc=0
|
||||
gen dis=0
|
||||
forvalues i=1/7 {
|
||||
forvalues j=`=`i'+1'/7 {
|
||||
replace conc=conc+1 if itemA`i'==itemA`j'
|
||||
replace conc=conc+1 if itemB`i'==itemB`j'
|
||||
}
|
||||
}
|
||||
forvalues i=1/7 {
|
||||
forvalues j=1/7 {
|
||||
replace dis=dis+1 if itemA`i'==itemB`j'
|
||||
}
|
||||
}
|
||||
gen result=.
|
||||
replace result=1 if conc==42&dis==0&result==.
|
||||
replace result=3 if conc<42&dis==0&result==.
|
||||
replace result=4 if dis>0&conc>0&result==.
|
||||
replace result=5 if dis==49&result==.
|
||||
egen nbcl=rowmax(item*)
|
||||
}
|
||||
if "`file'"=="result" {
|
||||
local text="CLV Classique"
|
||||
}
|
||||
if "`file'"=="result2" {
|
||||
local text="CLV Classique 2e choix"
|
||||
}
|
||||
if "`file'"=="resultpoly" {
|
||||
local text="CLV Polychoric"
|
||||
}
|
||||
if "`file'"=="resultpoly2" {
|
||||
local text="CLV Polychoric 2e choix"
|
||||
}
|
||||
if "`file'"=="result2nd" {
|
||||
local text="CLV 2nd ordre "
|
||||
}
|
||||
if "`file'"=="result2nd2" {
|
||||
local text="CLV 2nd ordre 2e choix"
|
||||
}
|
||||
di in gr "`text'"
|
||||
tab result
|
||||
}
|
||||
|
||||
end
|
168
Modules/ado/personal/t/todate.ado
Normal file
168
Modules/ado/personal/t/todate.ado
Normal file
@ -0,0 +1,168 @@
|
||||
*! 1.3.0 NJC 6 Sept 2005
|
||||
* 1.2.1 NJC 29 July 2003
|
||||
* 1.2.0 NJC 4 July 2001
|
||||
* 1.1.0 NJC 7 June 2001
|
||||
program todate
|
||||
version 8
|
||||
syntax varlist [if] [in], Pattern(string) Generate(string) ///
|
||||
[ Format(string) Cend(numlist int >200 <=10000 max=1) ]
|
||||
|
||||
// existing and new varlists
|
||||
tokenize `varlist'
|
||||
local nvars : word count `varlist'
|
||||
|
||||
// do before second -syntax-
|
||||
marksample touse, novarlist
|
||||
|
||||
local 0 "`generate'"
|
||||
syntax newvarlist
|
||||
|
||||
if `nvars' != `: word count `varlist'' {
|
||||
di as err "number of new variables not equal to" _c
|
||||
di as err " number of existing variables"
|
||||
exit 198
|
||||
}
|
||||
|
||||
// partial test of format
|
||||
if "`format'" != "" {
|
||||
capture display `format' 1
|
||||
if _rc {
|
||||
di as err "invalid format()"
|
||||
exit 120
|
||||
}
|
||||
}
|
||||
|
||||
// parse pattern into m d y h q w elements
|
||||
// indulge upper case
|
||||
local pattern = lower("`pattern'")
|
||||
local plength = length("`pattern'")
|
||||
|
||||
forval i = 1 / `plength' {
|
||||
local p = substr("`pattern'",`i',1)
|
||||
|
||||
if "`p'" == "m" local mlist "`mlist' `i'"
|
||||
else if "`p'" == "d" local dlist "`dlist' `i'"
|
||||
else if "`p'" == "y" local ylist "`ylist' `i'"
|
||||
else if "`p'" == "h" local hlist "`hlist' `i'"
|
||||
else if "`p'" == "q" local qlist "`qlist' `i'"
|
||||
else if "`p'" == "w" local wlist "`wlist' `i'"
|
||||
else {
|
||||
di as err "invalid pattern"
|
||||
exit 198
|
||||
}
|
||||
}
|
||||
|
||||
// allow mdy yh yq ym yw permutations
|
||||
foreach i in m d y h q w {
|
||||
if "``i'list'" != "" {
|
||||
local ptype "`ptype'`i'"
|
||||
local pels "`pels' `i'"
|
||||
}
|
||||
}
|
||||
|
||||
if !inlist("`ptype'", "yh", "yq", "my", "yw", "mdy") {
|
||||
di as err "invalid pattern type: `ptype'"
|
||||
exit 198
|
||||
}
|
||||
if "`ptype'" == "my" local ptype "ym"
|
||||
|
||||
// contiguous digits will have range == # elements - 1
|
||||
foreach i in `pels' {
|
||||
local `i'1 : word 1 of ``i'list'
|
||||
local `i'len : word count ``i'list'
|
||||
local last : word ``i'len' of ``i'list'
|
||||
local range = `last' - ``i'1'
|
||||
local range2 = ``i'len' - 1
|
||||
if `range' != `range2' {
|
||||
di as err "`i' digits not contiguous in pattern"
|
||||
exit 198
|
||||
}
|
||||
}
|
||||
|
||||
// year digits and cend() compatible?
|
||||
if `ylen' != 4 & "`cend'" == "" {
|
||||
di as err "`ylen' digit years: need cend() option?"
|
||||
exit 198
|
||||
}
|
||||
else if `ylen' == 4 & "`cend'" != "" {
|
||||
di as txt "4 digit years: cend() option ignored"
|
||||
local cend
|
||||
}
|
||||
|
||||
// for each variable in original varlist
|
||||
qui forval i = 1 / `nvars' {
|
||||
tempvar strdate datelen touse2
|
||||
|
||||
// markout separately for each variable
|
||||
gen byte `touse2' = `touse'
|
||||
markout `touse2' ``i'', strok
|
||||
|
||||
// working string variable copy of date variable
|
||||
capture confirm string variable ``i''
|
||||
if _rc gen `strdate' = string(``i'',"%12.0g") if `touse2'
|
||||
else gen `strdate' = trim(``i'') if `touse2'
|
||||
local v "``i''"
|
||||
local `i' "`strdate'"
|
||||
|
||||
// how long is date variable?
|
||||
gen `datelen' = length(``i'')
|
||||
su `datelen' if `touse2', meanonly
|
||||
local range = r(max) - r(min)
|
||||
local min = r(min)
|
||||
local max = r(max)
|
||||
|
||||
if `max' != `plength' {
|
||||
noi di as res "`v': " ///
|
||||
as txt "length does not match pattern"
|
||||
continue
|
||||
}
|
||||
|
||||
// range == 0 is no problem
|
||||
if `range' == 1 { /* leading zero needs to be supplied? */
|
||||
replace `strdate' = "0" + `strdate' ///
|
||||
if `datelen' == `min' & `touse2'
|
||||
}
|
||||
else if `range' >= 2 { /* range of lengths >= 2 => skip this */
|
||||
noi di as res "`v': " ///
|
||||
as txt "length too variable to handle"
|
||||
continue
|
||||
}
|
||||
|
||||
// construct month, day, year, half, quarter, week as needed
|
||||
foreach j in `pels' {
|
||||
tempvar `j'
|
||||
gen ``j'' = real(substr(``i'',``j'1',``j'len'))
|
||||
}
|
||||
|
||||
if "`cend'" != "" {
|
||||
local c1 = int(`cend' / 100)
|
||||
local c2 = mod(`cend',100)
|
||||
replace `y' = ///
|
||||
`y' + 100 * cond(`y' <= `c2', `c1', `c1' - 1)
|
||||
}
|
||||
|
||||
// generate new variable
|
||||
local newvar : word `i' of `varlist'
|
||||
if "`ptype'" == "mdy" {
|
||||
gen `newvar' = mdy(`m',`d',`y') if `touse2'
|
||||
}
|
||||
else {
|
||||
local o = substr("`ptype'",2,1)
|
||||
gen `newvar' = y`o'(`y',``o'') if `touse2'
|
||||
}
|
||||
|
||||
if "`format'" != "" format `format' `newvar'
|
||||
else {
|
||||
if index("`ptype'", "d") format %d `newvar'
|
||||
else if index("`ptype'", "w") format %tw `newvar'
|
||||
else if index("`ptype'", "m") format %tm `newvar'
|
||||
else if index("`ptype'", "q") format %tq `newvar'
|
||||
else if index("`ptype'", "h") format %th `newvar'
|
||||
}
|
||||
|
||||
_crcslbl `newvar' ``i''
|
||||
|
||||
drop `touse2'
|
||||
}
|
||||
end
|
||||
|
10
Modules/ado/personal/t/torumm.ado
Normal file
10
Modules/ado/personal/t/torumm.ado
Normal file
@ -0,0 +1,10 @@
|
||||
program define torumm
|
||||
syntax varlist ,File(string) [Replace msp]
|
||||
tempname string
|
||||
egen `string'=concat(`varlist')
|
||||
if "`msp'"=="" {
|
||||
replace `string'=subinstr(`string',"."," ",.)
|
||||
}
|
||||
*tab `string'
|
||||
outsheet `string' using "`file'", `replace' nonames noquote
|
||||
end
|
29
Modules/ado/personal/t/tosas.ado
Normal file
29
Modules/ado/personal/t/tosas.ado
Normal file
@ -0,0 +1,29 @@
|
||||
program define tosas,eclass
|
||||
version 10.0
|
||||
syntax [varlist] [if] [in] [,Name(string) pgm(string) Batch]
|
||||
preserve
|
||||
if "`if'"!=""|"`in'"!="" {
|
||||
qui keep `if' `in'
|
||||
}
|
||||
local dir=c(tmpdir)
|
||||
tempfile tosasfile totsasfile
|
||||
qui outsheet `varlist' using "`tosasfile'.txt",replace
|
||||
qui outsheet `varlist' using "d:\essai.txt",replace
|
||||
if "`name'"=="" {
|
||||
local name stata
|
||||
}
|
||||
drop _all
|
||||
qui set obs 1000
|
||||
qui gen txt=""
|
||||
qui replace txt="PROC IMPORT OUT=WORK.`name' DATAFILE='`tosasfile'.txt' DBMS=TAB REPLACE;GETNAMES=YES;DATAROW=2; RUN;" in 3
|
||||
qui replace txt="`pgm'" in 4
|
||||
qui outsheet txt using "`tosasfile'_pgmsas.txt", replace nonames noquote
|
||||
if "`batch'"!="" {
|
||||
shell "C:\Program Files\SAS\SASFoundation\9.3\sas.exe" "`tosasfile'_pgmsas.txt" -print "`tosasfile'.lst" -nolog
|
||||
view "`tosasfile'.lst"
|
||||
}
|
||||
else {
|
||||
shell "C:\Program Files\SASHome\SASFoundation\9.3\core\sasexe\SASOACT.EXE" action=Submit datatype=SASFile filename="`tosasfile'_pgmsas.txt" progid=SAS.Application.903
|
||||
}
|
||||
restore
|
||||
end
|
346
Modules/ado/personal/t/traces v4.ado
Normal file
346
Modules/ado/personal/t/traces v4.ado
Normal file
@ -0,0 +1,346 @@
|
||||
*! Version 4 22January2015
|
||||
************************************************************************************************************
|
||||
* Traces: Traces of items
|
||||
* Version 4: January 22, 2015 /*ICC*/
|
||||
*
|
||||
* Historic:
|
||||
* Version 1 (2003-06-29): Jean-Benoit Hardouin
|
||||
* Version 2 (2003-07-04): Jean-Benoit Hardouin
|
||||
* version 3 (2003-07-09): Jean-Benoit Hardouin
|
||||
* Version 3.1 (2005-06-07): Jean-Benoit Hardouin /*small modifications*/
|
||||
* Version 3.2: May 27, 2007 /*onlyone option*/
|
||||
* Version 3.3: October 16, 2012 /*minor modifications*/
|
||||
*
|
||||
* Jean-benoit Hardouin, phD, Assistant Professor
|
||||
* Team of Biostatistics, Clinical Research and Subjective Measures in Health Sciences
|
||||
* University of Nantes - Faculty of Pharmaceutical Sciences
|
||||
* France
|
||||
* jean-benoit.hardouin@anaqol.org
|
||||
*
|
||||
* News about this program :http://www.anaqol.org
|
||||
* FreeIRT Project website : http://www.freeirt.org
|
||||
*
|
||||
* Copyright 2003, 2005, 2007, 2012, 2015 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 traces, rclass
|
||||
version 8.0
|
||||
syntax varlist(numeric min=2) [, COMPare(varlist min=2 max=2) ICC SAVeicc noGraph Score Test Restscore Logistic CI CUMulative REPFiles(string) SCOREFiles(string) RESTSCOREFiles(string) LOGISTICFile(string) noDraw noDRAWComb REPlace ONLYone(string) THResholds(string) Black]
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
if "`onlyone'"!=""&"`drawcomb'"!="" {
|
||||
local drawcomb
|
||||
}
|
||||
|
||||
tempvar varscore
|
||||
qui gen `varscore'=0
|
||||
label variable `varscore' "Total score"
|
||||
local scoremax=0
|
||||
local flag=0
|
||||
|
||||
if "`score'"==""&"`restscore'"==""&&"`logistic'"=="" {
|
||||
local score="score"
|
||||
}
|
||||
|
||||
local modamax=0
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `varscore'=`varscore'+``i''
|
||||
qui su ``i''
|
||||
local modamax`i'=r(max)
|
||||
if r(min)!=0 {
|
||||
local flag=1
|
||||
}
|
||||
local scoremax=`scoremax'+`modamax`i''
|
||||
if `modamax`i''!=1 {
|
||||
local flagbin=0
|
||||
}
|
||||
if `modamax`i''>`modamax' {
|
||||
local modamax=`modamax`i''
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if `flag'==1 {
|
||||
di as error "The lower modality of the item must be 0"
|
||||
exit
|
||||
}
|
||||
if "`flagbin'"!=""&"`logistic'"!="" {
|
||||
di as error "The logistic option is not possible with polytomous items"
|
||||
exit
|
||||
}
|
||||
|
||||
qui su `varscore'
|
||||
local maxscore=r(max)
|
||||
|
||||
forvalues i=0/`maxscore' {
|
||||
qui count if `varscore'==`i'
|
||||
local nscore`i'=r(N)
|
||||
}
|
||||
|
||||
|
||||
global score
|
||||
global restscore
|
||||
global logistic
|
||||
qui count
|
||||
local N=r(N)
|
||||
if `c(matsize)'<`N'&"`saveicc'"!="" {
|
||||
set matsize `N'
|
||||
}
|
||||
|
||||
|
||||
if "`score'"!="" {
|
||||
if "`thresholds'"!="" {
|
||||
* set trace on
|
||||
local nbth:word count `thresholds'
|
||||
forvalues t=1/`nbth' {
|
||||
local th`t':word `t' of `thresholds'
|
||||
}
|
||||
tempname label
|
||||
local recode 0/`th1'=1 `=`th`nbth''+1'/max=`=`nbth'+1'
|
||||
qui label define `label' 1 "0/`th1'",add
|
||||
qui label define `label' `=`nbth'+1' "`=`th`nbth''+1'/max",add
|
||||
forvalues j=2/`nbth' {
|
||||
local recode `recode' `=`th`=`j'-1''+1'/`th`j''=`j'
|
||||
qui label define `label' `j' "`=`th`=`j'-1''+1'/`th`j''",add
|
||||
}
|
||||
tempname varscore2
|
||||
qui gen `varscore2'=`varscore'
|
||||
qui recode `varscore' `recode'
|
||||
qui label values `varscore' `label'
|
||||
local nbgroups=`nbth'+1
|
||||
local minimum=1
|
||||
}
|
||||
else {
|
||||
local nbgroups=`maxscore'
|
||||
local minimum=0
|
||||
}
|
||||
local listicc
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
local y`i'
|
||||
tempvar icc``i''
|
||||
gen `icc``i'''=0
|
||||
local listicc `listicc' `icc``i'''
|
||||
forvalues k=1/`modamax`i'' {
|
||||
tempvar propscore`i'`k' tmp
|
||||
if "`cumulative'"!="" {
|
||||
qui gen `tmp'=``i''>=`k'&``i''!=.
|
||||
bysort `varscore' : egen `propscore`i'`k''=mean(`tmp')
|
||||
label variable `propscore`i'`k'' "Item ``i''>=`k'"
|
||||
}
|
||||
else {
|
||||
qui gen `tmp'=``i''==`k'&``i''!=.
|
||||
bysort `varscore' : egen `propscore`i'`k''=mean(`tmp')
|
||||
label variable `propscore`i'`k'' "Item ``i''=`k'"
|
||||
*di "replace icc``i''=icc``i''+`k'*`propscore`i'`k''"
|
||||
qui replace `icc``i'''=`icc``i'''+`k'*`propscore`i'`k''
|
||||
}
|
||||
local y`i'="`y`i'' `propscore`i'`k''"
|
||||
local style="solid"
|
||||
local color="black"
|
||||
local width="medthick"
|
||||
if `modamax`i''==1&"`ci'"!="" {
|
||||
tempvar icscoreminus icscoreplus
|
||||
forvalues l=1/`maxscore' {
|
||||
qui count if `varscore'==`l'
|
||||
local nscore`l'=r(N)
|
||||
}
|
||||
qui gen `icscoreminus'=`propscore`i'1'-1.96*sqrt(`propscore`i'1'*(1-`propscore`i'1')/`nscore1')
|
||||
qui gen `icscoreplus'=`propscore`i'1'+1.96*sqrt(`propscore`i'1'*(1-`propscore`i'1')/`nscore1')
|
||||
label variable `icscoreminus' "Lower 95% confidence interval"
|
||||
label variable `icscoreplus' "Upper 95% confidence interval"
|
||||
local y`i'="`icscoreminus' `icscoreplus' `propscore`i'1'"
|
||||
local style="dash dash solid"
|
||||
local color="red red black"
|
||||
local width="thin thin medthick"
|
||||
}
|
||||
if `modamax`i''==1&"`test'"!="" {
|
||||
qui regress `propscore`i'1' `varscore'
|
||||
local p=Fden(e(df_m),e(df_r),e(F))
|
||||
if `p'<0.0001 {
|
||||
local note="Test: slope=0, p<0.0001"
|
||||
}
|
||||
else {
|
||||
local p=substr("`p'",1,6)
|
||||
local note="Test: slope=0, p=`p'"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ("``i''"=="`onlyone'"|"`onlyone'"=="")&"`nograph'"=="" {
|
||||
qui graph twoway (line `y`i'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , note("`note'") ylabel(0(.25)1) xlabel(`minimum'(1)`nbgroups',valuelabel) name(score`i',replace) title("Trace of the item ``i'' as a function of the score") ytitle("Rate of positive response") `draw' /*areastyle(none)*/
|
||||
}
|
||||
if ("``i''"=="`onlyone'"|"`onlyone'"=="")&"`icc'"!=""&"`nograph'"!=""{
|
||||
qui graph twoway (line `icc``i''' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , ylabel(0(.5)`modamax`i'') xlabel(`minimum'(1)`nbgroups',valuelabel) name(icc`i',replace) title("Approximate ICC of the item ``i'' as a function of the score") ytitle("Mean response") `draw' /*areastyle(none)*/
|
||||
}
|
||||
global score "$score score`i'"
|
||||
if "`scorefiles'"!="" {
|
||||
graph save score`i' `repfiles'\\`scorefiles'``i'' ,`replace'
|
||||
}
|
||||
}
|
||||
if "`saveicc'"!="" {
|
||||
local listicc `listicc' `varscore'
|
||||
tempname matscore
|
||||
mkmat `listicc',matrix(`matscore')
|
||||
}
|
||||
if "`thresholds'"!="" {
|
||||
qui replace `varscore'=`varscore2'
|
||||
}
|
||||
}
|
||||
if "`compare'"!=""&"`nograph'"!="" {
|
||||
local tmp1 : word 1 of `compare'
|
||||
local tmp2 : word 2 of `compare'
|
||||
di "compare `compare' tmp1 `tmp1' tmp2 `tmp2'"
|
||||
label variable `icc`tmp1'' `tmp1'
|
||||
label variable `icc`tmp2'' `tmp2'
|
||||
di "qui graph twoway (line `icc`tmp1'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) (line `icc`tmp2'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , ylabel(0(.5)`modamax') xlabel(`minimum'(1)`nbgroups',valuelabel) name(score`i',replace) title(Comparison of the ICC of the items `tmp1' and `tmp2') `draw' /*areastyle(none)*/"
|
||||
qui graph twoway (line `icc`tmp1'' `varscore', clpattern(`style') clcolor(blue red) clwidth(`width')) (line `icc`tmp2'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , ylabel(0(.5)`modamax') xlabel(`minimum'(1)`nbgroups',valuelabel) /*name(score`i',replace)*/ title("Comparison of the ICC of the items `tmp1' and `tmp2'") ytitle("Mean response") /*areastyle(none)*/
|
||||
}
|
||||
if "`restscore'"!="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
local y`i'
|
||||
tempvar restscore`i'
|
||||
qui gen `restscore`i''=`varscore'-``i''
|
||||
label variable `restscore`i'' "Rest score with respect to the item ``i''"
|
||||
if "`thresholds'"!="" {
|
||||
* set trace on
|
||||
local nbth:word count `thresholds'
|
||||
forvalues t=1/`nbth' {
|
||||
local th`t':word `t' of `thresholds'
|
||||
}
|
||||
tempname label
|
||||
local recode 0/`th1'=1 `=`th`nbth''+1'/max=`=`nbth'+1'
|
||||
qui label define `label' 1 "0/`th1'",add
|
||||
qui label define `label' `=`nbth'+1' "`=`th`nbth''+1'/max",add
|
||||
forvalues j=2/`nbth' {
|
||||
local recode `recode' `=`th`=`j'-1''+1'/`th`j''=`j'
|
||||
qui label define `label' `j' "`=`th`=`j'-1''+1'/`th`j''",add
|
||||
}
|
||||
|
||||
*di "recode `restscore`i'' `recode'"
|
||||
qui recode `restscore`i'' `recode'
|
||||
qui label values `restscore`i'' `label'
|
||||
local nbgroups=`nbth'+1
|
||||
local minimum=1
|
||||
}
|
||||
else {
|
||||
local nbgroups=`maxscore'
|
||||
local minimum=0
|
||||
}
|
||||
|
||||
forvalues k=1/`modamax`i'' {
|
||||
tempvar rtmp proprestscore`i'`k'
|
||||
if "`cumulative'"!="" {
|
||||
qui gen `rtmp'=``i''>=`k'&``i''!=.
|
||||
bysort `restscore`i'': egen `proprestscore`i'`k''=mean(`rtmp')
|
||||
label variable `proprestscore`i'`k'' "Item ``i''>=`k'"
|
||||
}
|
||||
else {
|
||||
qui gen `rtmp'=``i''==`k'&``i''!=.
|
||||
bysort `restscore`i'': egen `proprestscore`i'`k''=mean(`rtmp')
|
||||
label variable `proprestscore`i'`k'' "Item ``i''=`k'"
|
||||
}
|
||||
local y`i'="`y`i'' `proprestscore`i'`k''"
|
||||
local style="solid"
|
||||
local color="black"
|
||||
local width="medthick"
|
||||
if `modamax`i''==1&"`ci'"!="" {
|
||||
tempvar icrestscoreminus icrestscoreplus
|
||||
qui su `restscore`i''
|
||||
local maxrestscore=r(max)
|
||||
forvalues l=1/`maxrestscore' {
|
||||
qui count if `restscore`i''==`l'
|
||||
local nrestscore`i'=r(N)
|
||||
}
|
||||
qui gen `icrestscoreminus'=`proprestscore`i'1'-1.96*sqrt(`proprestscore`i'1'*(1-`proprestscore`i'1')/`nrestscore`i'')
|
||||
qui gen `icrestscoreplus'=`proprestscore`i'1'+1.96*sqrt(`proprestscore`i'1'*(1-`proprestscore`i'1')/`nrestscore`i'')
|
||||
label variable `icrestscoreminus' "Lower 95% confidence interval"
|
||||
label variable `icrestscoreplus' "Upper 95% confidence interval"
|
||||
local y`i'="`icrestscoreminus' `icrestscoreplus' `proprestscore`i'1'"
|
||||
local style="dash dash solid"
|
||||
local color="red red black"
|
||||
local width="thin thin medthick"
|
||||
}
|
||||
if `modamax`i''==1&"`test'"!="" {
|
||||
qui regress `proprestscore`i'1' `varscore'
|
||||
local p=Fden(e(df_m),e(df_r),e(F))
|
||||
if `p'<0.0001 {
|
||||
local note="Test: slope=0, p<0.0001"
|
||||
}
|
||||
else {
|
||||
local p=substr("`p'",1,6)
|
||||
local note="Test: slope=0, p=`p'"
|
||||
}
|
||||
}
|
||||
}
|
||||
local restscoremax=`scoremax'-`modamax`i''
|
||||
if ("``i''"=="`onlyone'"|"`onlyone'"=="")&"`nograph'"!="" {
|
||||
*tab `proprestscore`i'1' `restscore`i''
|
||||
qui graph twoway (line `y`i'' `restscore`i'', clpattern(`style') clcolor(`color') clwidth(`width')), note("`note'") ylabel(0(0.25)1) xlabel(`minimum'(1)`nbgroups',valuelabel) name(restscore`i',replace) title("Trace of the item ``i'' as a function of the restscore") ytitle("Rate of positive response") `draw'
|
||||
}
|
||||
global restscore "$restscore restscore`i'"
|
||||
if "`restscorefiles'"!="" {
|
||||
graph save restscore`i' `repfiles'\\`restscorefiles'``i'' ,`replace'
|
||||
}
|
||||
}
|
||||
}
|
||||
if "logistic"!="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
qui logistic ``i'' `varscore'
|
||||
tempname coef
|
||||
matrix `coef'=e(b)
|
||||
local pente`i'=`coef'[1,1]
|
||||
local intercept`i'=`coef'[1,2]
|
||||
tempvar logit`i'
|
||||
qui gen `logit`i''=exp(`intercept`i''+`pente`i''*`varscore')/(1+exp(`intercept`i''+`pente`i''*`varscore'))
|
||||
label variable `logit`i'' "Item ``i''"
|
||||
sort `varscore'
|
||||
global logistic "$logistic `logit`i''"
|
||||
}
|
||||
}
|
||||
if "`drawcomb'"!="" {
|
||||
local drawcomb="nodraw"
|
||||
}
|
||||
|
||||
if ("`score'"!=""&"`onlyone'"=="")&"`nograph'"!="" {
|
||||
graph combine $score , title("Trace of the items as a function of the score") name(score,replace) `drawcomb'
|
||||
if "`scorefiles'"!="" {
|
||||
graph save score `repfiles'\\`scorefiles' ,`replace'
|
||||
}
|
||||
}
|
||||
|
||||
if ("`restscore'"!=""&"`onlyone'"=="")&"`nograph'"!="" {
|
||||
graph combine $restscore , title("Trace of the items as a function of the restscores") name(restscore,replace) `drawcomb'
|
||||
if "`restscorefiles'"!="" {
|
||||
graph save restscore `repfiles'\\`restscorefiles' ,`replace'
|
||||
}
|
||||
}
|
||||
if ("`logistic'"!="")&"`nograph'"!="" {
|
||||
graph twoway (line $logistic `varscore'), ylabel(0(0.25)1) xlabel(0(1)`nbitems') title("Logistic traces") ytitle("") name(logistic,replace) `drawcomb'
|
||||
if "`logisticfile'"!="" {
|
||||
graph save logistic `repfiles'\\`logisticfile' ,`replace'
|
||||
}
|
||||
}
|
||||
if "`saveicc'"!="" {
|
||||
return matrix matscore=`matscore'
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -0,0 +1,357 @@
|
||||
*! Version 5 5March2016
|
||||
************************************************************************************************************
|
||||
* Traces: Traces of items
|
||||
* Version 5: March 5, 2016 /*numerical items*/
|
||||
*
|
||||
* Historic:
|
||||
* Version 1 (2003-06-29): Jean-Benoit Hardouin
|
||||
* Version 2 (2003-07-04): Jean-Benoit Hardouin
|
||||
* version 3 (2003-07-09): Jean-Benoit Hardouin
|
||||
* Version 3.1 (2005-06-07): Jean-Benoit Hardouin /*small modifications*/
|
||||
* Version 3.2: May 27, 2007 /*onlyone option*/
|
||||
* Version 3.3: October 16, 2012 /*minor modifications*/
|
||||
* Version 4: January 22, 2015 /*ICC*/
|
||||
*
|
||||
* Jean-benoit Hardouin, phD, Assistant Professor
|
||||
* EA4275-SPHERE "MethodS in Patients-centered outcomes and HEalth ResEarches"
|
||||
* University of Nantes - Faculty of Pharmaceutical Sciences
|
||||
* France
|
||||
* jean-benoit.hardouin@anaqol.org
|
||||
*
|
||||
* News about this program :http://www.anaqol.org
|
||||
* FreeIRT Project website : http://www.freeirt.org
|
||||
*
|
||||
* Copyright 2003, 2005, 2007, 2012, 2015, 2016 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 traces, rclass
|
||||
version 8.0
|
||||
syntax varlist(numeric min=2) [, COMPare(varlist min=2 max=2) ICC SAVeicc noGraph Score Test Restscore Logistic CI CUMulative REPFiles(string) SCOREFiles(string) RESTSCOREFiles(string) LOGISTICFile(string) noDraw noDRAWComb REPlace ONLYone(string) THResholds(string) Black]
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
if "`onlyone'"!=""&"`drawcomb'"!="" {
|
||||
local drawcomb
|
||||
}
|
||||
|
||||
tempvar varscore
|
||||
qui gen `varscore'=0
|
||||
label variable `varscore' "Total score"
|
||||
local scoremax=0
|
||||
local flag=0
|
||||
|
||||
if "`score'"==""&"`restscore'"==""&&"`logistic'"=="" {
|
||||
local score="score"
|
||||
}
|
||||
|
||||
local modamax=-999
|
||||
local modamin=999
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `varscore'=`varscore'+``i''
|
||||
qui su ``i''
|
||||
local modamax`i'=r(max)
|
||||
local modamin`i'=r(min)
|
||||
if r(min)!=0 {
|
||||
local flag=1
|
||||
}
|
||||
local scoremax=`scoremax'+`modamax`i''
|
||||
if `modamax`i''!=1 {
|
||||
local flagbin=0
|
||||
}
|
||||
if `modamax`i''>`modamax' {
|
||||
local modamax=`modamax`i''
|
||||
}
|
||||
if `modamin`i''<`modamin' {
|
||||
local modamin=`modamin`i''
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if `flag'==1 {
|
||||
di as error "The lower modality of the item must be 0"
|
||||
exit
|
||||
}
|
||||
*/
|
||||
if "`flagbin'"!=""&"`logistic'"!="" {
|
||||
di as error "The logistic option is not possible with polytomous items"
|
||||
exit
|
||||
}
|
||||
|
||||
qui su `varscore'
|
||||
local maxscore=r(max)
|
||||
local minscore=r(min)
|
||||
|
||||
forvalues i=`minscore'/`maxscore' {
|
||||
qui count if `varscore'>`=`i'-0.5'&`varscore'<=`=`i'+0.5'
|
||||
local nscore`i'=r(N)
|
||||
}
|
||||
|
||||
|
||||
global score
|
||||
global restscore
|
||||
global logistic
|
||||
qui count
|
||||
local N=r(N)
|
||||
if `c(matsize)'<`N'&"`saveicc'"!="" {
|
||||
set matsize `N'
|
||||
}
|
||||
|
||||
|
||||
if "`score'"!="" {
|
||||
if "`thresholds'"!="" {
|
||||
* set trace on
|
||||
local nbth:word count `thresholds'
|
||||
forvalues t=1/`nbth' {
|
||||
local th`t':word `t' of `thresholds'
|
||||
}
|
||||
tempname label
|
||||
local recode min/`th1'=1 `=`th`nbth''+1'/max=`=`nbth'+1'
|
||||
qui label define `label' 1 "min/`th1'",add
|
||||
qui label define `label' `=`nbth'+1' "`=`th`nbth''+1'/max",add
|
||||
forvalues j=2/`nbth' {
|
||||
local recode `recode' `=`th`=`j'-1''+1'/`th`j''=`j'
|
||||
qui label define `label' `j' "`=`th`=`j'-1''+1'/`th`j''",add
|
||||
}
|
||||
tempname varscore2
|
||||
qui gen `varscore2'=`varscore'
|
||||
qui recode `varscore' `recode'
|
||||
qui label values `varscore' `label'
|
||||
local nbgroups=`nbth'+1
|
||||
local minimum=1
|
||||
}
|
||||
else {
|
||||
local nbgroups=`maxscore'
|
||||
local minimum=0
|
||||
}
|
||||
local listicc
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
local y`i'
|
||||
tempvar icc``i''
|
||||
gen `icc``i'''=0
|
||||
local listicc `listicc' `icc``i'''
|
||||
local l=0
|
||||
forvalues k=`=`modamin`i''+1'/`modamax`i'' {
|
||||
tempvar propscore`i'`l' tmp
|
||||
if "`cumulative'"!="" {
|
||||
qui gen `tmp'=``i''>=`k'&``i''!=.
|
||||
bysort `varscore' : egen `propscore`i'`l''=mean(`tmp')
|
||||
label variable `propscore`i'`l'' "Item ``i''>=`k'"
|
||||
}
|
||||
else {
|
||||
qui gen `tmp'=``i''==`k'&``i''!=.
|
||||
bysort `varscore' : egen `propscore`i'`l''=mean(`tmp')
|
||||
label variable `propscore`i'`l'' "Item ``i''=`k'"
|
||||
*di "replace icc``i''=icc``i''+`k'*`propscore`i'`k''"
|
||||
qui replace `icc``i'''=`icc``i'''+`k'*`propscore`i'`l''
|
||||
}
|
||||
local y`i'="`y`i'' `propscore`i'`l''"
|
||||
local style="solid"
|
||||
local color="black"
|
||||
local width="medthick"
|
||||
if `modamax`i''==1&"`ci'"!="" {
|
||||
tempvar icscoreminus icscoreplus
|
||||
forvalues m=1/`maxscore' {
|
||||
qui count if `varscore'==`m'
|
||||
local nscore`m'=r(N)
|
||||
}
|
||||
qui gen `icscoreminus'=`propscore`i'1'-1.96*sqrt(`propscore`i'1'*(1-`propscore`i'1')/`nscore1')
|
||||
qui gen `icscoreplus'=`propscore`i'1'+1.96*sqrt(`propscore`i'1'*(1-`propscore`i'1')/`nscore1')
|
||||
label variable `icscoreminus' "Lower 95% confidence interval"
|
||||
label variable `icscoreplus' "Upper 95% confidence interval"
|
||||
local y`i'="`icscoreminus' `icscoreplus' `propscore`i'1'"
|
||||
local style="dash dash solid"
|
||||
local color="red red black"
|
||||
local width="thin thin medthick"
|
||||
}
|
||||
if `modamax`i''==1&"`test'"!="" {
|
||||
qui regress `propscore`i'1' `varscore'
|
||||
local p=Fden(e(df_m),e(df_r),e(F))
|
||||
if `p'<0.0001 {
|
||||
local note="Test: slope=0, p<0.0001"
|
||||
}
|
||||
else {
|
||||
local p=substr("`p'",1,6)
|
||||
local note="Test: slope=0, p=`p'"
|
||||
}
|
||||
}
|
||||
local ++l
|
||||
}
|
||||
|
||||
if ("``i''"=="`onlyone'"|"`onlyone'"=="")&"`graph'"=="" {
|
||||
qui graph twoway (line `y`i'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , note("`note'") ylabel(0(.25)1) xlabel(`minimum'(1)`nbgroups',valuelabel) name(score`i',replace) title("Trace of the item ``i'' as a function of the score") ytitle("Rate of positive response") `draw' /*areastyle(none)*/
|
||||
}
|
||||
if ("``i''"=="`onlyone'"|"`onlyone'"=="")&"`icc'"!=""&"`graph'"==""{
|
||||
qui graph twoway (line `icc``i''' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , ylabel(0(.5)`modamax`i'') xlabel(`minimum'(1)`nbgroups',valuelabel) name(icc`i',replace) title("Approximate ICC of the item ``i'' as a function of the score") ytitle("Mean response") `draw' /*areastyle(none)*/
|
||||
}
|
||||
global score "$score score`i'"
|
||||
if "`scorefiles'"!="" {
|
||||
graph save score`i' `repfiles'\\`scorefiles'``i'' ,`replace'
|
||||
}
|
||||
}
|
||||
if "`saveicc'"!="" {
|
||||
local listicc `listicc' `varscore'
|
||||
tempname matscore
|
||||
mkmat `listicc',matrix(`matscore')
|
||||
}
|
||||
if "`thresholds'"!="" {
|
||||
qui replace `varscore'=`varscore2'
|
||||
}
|
||||
}
|
||||
if "`compare'"!=""&"`nograph'"!="" {
|
||||
local tmp1 : word 1 of `compare'
|
||||
local tmp2 : word 2 of `compare'
|
||||
di "compare `compare' tmp1 `tmp1' tmp2 `tmp2'"
|
||||
label variable `icc`tmp1'' `tmp1'
|
||||
label variable `icc`tmp2'' `tmp2'
|
||||
di "qui graph twoway (line `icc`tmp1'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) (line `icc`tmp2'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , ylabel(0(.5)`modamax') xlabel(`minimum'(1)`nbgroups',valuelabel) name(score`i',replace) title(Comparison of the ICC of the items `tmp1' and `tmp2') `draw' /*areastyle(none)*/"
|
||||
qui graph twoway (line `icc`tmp1'' `varscore', clpattern(`style') clcolor(blue red) clwidth(`width')) (line `icc`tmp2'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , ylabel(0(.5)`modamax') xlabel(`minimum'(1)`nbgroups',valuelabel) /*name(score`i',replace)*/ title("Comparison of the ICC of the items `tmp1' and `tmp2'") ytitle("Mean response") /*areastyle(none)*/
|
||||
}
|
||||
if "`restscore'"!="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
local y`i'
|
||||
tempvar restscore`i'
|
||||
qui gen `restscore`i''=`varscore'-``i''
|
||||
label variable `restscore`i'' "Rest score with respect to the item ``i''"
|
||||
if "`thresholds'"!="" {
|
||||
* set trace on
|
||||
local nbth:word count `thresholds'
|
||||
forvalues t=1/`nbth' {
|
||||
local th`t':word `t' of `thresholds'
|
||||
}
|
||||
tempname label
|
||||
local recode 0/`th1'=1 `=`th`nbth''+1'/max=`=`nbth'+1'
|
||||
qui label define `label' 1 "min/`th1'",add
|
||||
qui label define `label' `=`nbth'+1' "`=`th`nbth''+1'/max",add
|
||||
forvalues j=2/`nbth' {
|
||||
local recode `recode' `=`th`=`j'-1''+1'/`th`j''=`j'
|
||||
qui label define `label' `j' "`=`th`=`j'-1''+1'/`th`j''",add
|
||||
}
|
||||
|
||||
*di "recode `restscore`i'' `recode'"
|
||||
qui recode `restscore`i'' `recode'
|
||||
qui label values `restscore`i'' `label'
|
||||
local nbgroups=`nbth'+1
|
||||
local minimum=1
|
||||
}
|
||||
else {
|
||||
local nbgroups=`maxscore'
|
||||
local minimum=0
|
||||
}
|
||||
|
||||
forvalues k=1/`modamax`i'' {
|
||||
tempvar rtmp proprestscore`i'`k'
|
||||
if "`cumulative'"!="" {
|
||||
qui gen `rtmp'=``i''>=`k'&``i''!=.
|
||||
bysort `restscore`i'': egen `proprestscore`i'`k''=mean(`rtmp')
|
||||
label variable `proprestscore`i'`k'' "Item ``i''>=`k'"
|
||||
}
|
||||
else {
|
||||
qui gen `rtmp'=``i''==`k'&``i''!=.
|
||||
bysort `restscore`i'': egen `proprestscore`i'`k''=mean(`rtmp')
|
||||
label variable `proprestscore`i'`k'' "Item ``i''=`k'"
|
||||
}
|
||||
local y`i'="`y`i'' `proprestscore`i'`k''"
|
||||
local style="solid"
|
||||
local color="black"
|
||||
local width="medthick"
|
||||
if `modamax`i''==1&"`ci'"!="" {
|
||||
tempvar icrestscoreminus icrestscoreplus
|
||||
qui su `restscore`i''
|
||||
local maxrestscore=r(max)
|
||||
forvalues l=1/`maxrestscore' {
|
||||
qui count if `restscore`i''==`l'
|
||||
local nrestscore`i'=r(N)
|
||||
}
|
||||
qui gen `icrestscoreminus'=`proprestscore`i'1'-1.96*sqrt(`proprestscore`i'1'*(1-`proprestscore`i'1')/`nrestscore`i'')
|
||||
qui gen `icrestscoreplus'=`proprestscore`i'1'+1.96*sqrt(`proprestscore`i'1'*(1-`proprestscore`i'1')/`nrestscore`i'')
|
||||
label variable `icrestscoreminus' "Lower 95% confidence interval"
|
||||
label variable `icrestscoreplus' "Upper 95% confidence interval"
|
||||
local y`i'="`icrestscoreminus' `icrestscoreplus' `proprestscore`i'1'"
|
||||
local style="dash dash solid"
|
||||
local color="red red black"
|
||||
local width="thin thin medthick"
|
||||
}
|
||||
if `modamax`i''==1&"`test'"!="" {
|
||||
qui regress `proprestscore`i'1' `varscore'
|
||||
local p=Fden(e(df_m),e(df_r),e(F))
|
||||
if `p'<0.0001 {
|
||||
local note="Test: slope=0, p<0.0001"
|
||||
}
|
||||
else {
|
||||
local p=substr("`p'",1,6)
|
||||
local note="Test: slope=0, p=`p'"
|
||||
}
|
||||
}
|
||||
}
|
||||
local restscoremax=`scoremax'-`modamax`i''
|
||||
if ("``i''"=="`onlyone'"|"`onlyone'"=="")&"`nograph'"!="" {
|
||||
*tab `proprestscore`i'1' `restscore`i''
|
||||
qui graph twoway (line `y`i'' `restscore`i'', clpattern(`style') clcolor(`color') clwidth(`width')), note("`note'") ylabel(0(0.25)1) xlabel(`minimum'(1)`nbgroups',valuelabel) name(restscore`i',replace) title("Trace of the item ``i'' as a function of the restscore") ytitle("Rate of positive response") `draw'
|
||||
}
|
||||
global restscore "$restscore restscore`i'"
|
||||
if "`restscorefiles'"!="" {
|
||||
graph save restscore`i' `repfiles'\\`restscorefiles'``i'' ,`replace'
|
||||
}
|
||||
}
|
||||
}
|
||||
if "`logistic'"!="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
qui logistic ``i'' `varscore'
|
||||
tempname coef
|
||||
matrix `coef'=e(b)
|
||||
local pente`i'=`coef'[1,1]
|
||||
local intercept`i'=`coef'[1,2]
|
||||
tempvar logit`i'
|
||||
qui gen `logit`i''=exp(`intercept`i''+`pente`i''*`varscore')/(1+exp(`intercept`i''+`pente`i''*`varscore'))
|
||||
label variable `logit`i'' "Item ``i''"
|
||||
sort `varscore'
|
||||
global logistic "$logistic `logit`i''"
|
||||
}
|
||||
}
|
||||
if "`drawcomb'"!="" {
|
||||
local drawcomb="nodraw"
|
||||
}
|
||||
|
||||
*di " (`score'!=&`onlyone'==)&`nograph'!= {"
|
||||
if ("`score'"!=""&"`onlyone'"=="")&"`nograph'"!="" {
|
||||
graph combine $score , title("Trace of the items as a function of the score") name(score,replace) `drawcomb'
|
||||
if "`scorefiles'"!="" {
|
||||
graph save score `repfiles'\\`scorefiles' ,`replace'
|
||||
}
|
||||
}
|
||||
|
||||
if ("`restscore'"!=""&"`onlyone'"=="")&"`nograph'"!="" {
|
||||
graph combine $restscore , title("Trace of the items as a function of the restscores") name(restscore,replace) `drawcomb'
|
||||
if "`restscorefiles'"!="" {
|
||||
graph save restscore `repfiles'\\`restscorefiles' ,`replace'
|
||||
}
|
||||
}
|
||||
if ("`logistic'"!="")&"`nograph'"!="" {
|
||||
graph twoway (line $logistic `varscore'), ylabel(0(0.25)1) xlabel(0(1)`nbitems') title("Logistic traces") ytitle("") name(logistic,replace) `drawcomb'
|
||||
if "`logisticfile'"!="" {
|
||||
graph save logistic `repfiles'\\`logisticfile' ,`replace'
|
||||
}
|
||||
}
|
||||
if "`saveicc'"!="" {
|
||||
return matrix matscore=`matscore'
|
||||
}
|
||||
end
|
||||
|
||||
|
429
Modules/ado/personal/t/traces.ado
Normal file
429
Modules/ado/personal/t/traces.ado
Normal file
@ -0,0 +1,429 @@
|
||||
*! Version 5.2 24September2019
|
||||
*!Jean-Benoit Hardouin
|
||||
*
|
||||
************************************************************************************************************
|
||||
* Traces: Traces of items
|
||||
*
|
||||
* Historic:
|
||||
* Version 1 (2003-06-29) [Jean-Benoit Hardouin]
|
||||
* Version 2 (2003-07-04 [Jean-Benoit Hardouin]
|
||||
* version 3 (2003-07-09) [Jean-Benoit Hardouin]
|
||||
* Version 3.1 (2005-06-07) [Jean-Benoit Hardouin] /*small modifications*/
|
||||
* Version 3.2: May 27, 2007 [Jean-Benoit Hardouin] /*onlyone option*/
|
||||
* Version 3.3: October 16, 2012 [Jean-Benoit Hardouin] /*minor modifications*/
|
||||
* Version 4: January 22, 2015 [Jean-Benoit Hardouin] /*ICC*/
|
||||
* Version 5: March 5, 2016 [Jean-Benoit Hardouin] /*numerical items*/
|
||||
* Version 5.1: July 13, 2019 [Jean-Benoit Hardouin] /*Bugs Corrections*/
|
||||
* Version 5.2: September 24, 2019 [Jean-Benoit Hardouin] /*Bugs Corrections*/
|
||||
*
|
||||
* Jean-benoit Hardouin, phD, Assistant Professor
|
||||
* INSERM UMR 1246-SPHERE "Methods in Patient Centered Outcomes and Health Research", Nantes University, University of Tours
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* News about this program :http://www.anaqol.org
|
||||
*
|
||||
* Copyright 2003, 2005, 2007, 2012, 2015, 2016, 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 traces, rclass
|
||||
version 8.0
|
||||
syntax varlist(numeric min=2) [, /*COMPare(varlist min=2 max=2*/ ICC noGraph Score Test Restscore Logistic CI CUMulative REPFiles(string) DIRSave(string) FILESave SCOREFiles(string) RESTSCOREFiles(string) LOGISTICFile(string) ICCFile(string) noDraw noDRAWComb REPlace ONLYone(string) THResholds(string) Black]
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
if "`onlyone'"!=""&"`drawcomb'"!="" {
|
||||
local drawcomb
|
||||
}
|
||||
|
||||
if "`repfiles'"!=""&"`dirsave'"=="" {
|
||||
local dirsave `repfile'
|
||||
}
|
||||
if "`filesave'"=="" {
|
||||
local saving
|
||||
}
|
||||
else {
|
||||
if "`dirsave'"=="" {
|
||||
local dirsave `c(pwd)'
|
||||
}
|
||||
if "`scorefiles'"=="" {
|
||||
local scorefiles score
|
||||
}
|
||||
if "`restscorefiles'"=="" {
|
||||
local restscorefiles restscore
|
||||
}
|
||||
if "`logicticfile'"=="" {
|
||||
local logisticfile logistic
|
||||
}
|
||||
if "`iccfiles'"=="" {
|
||||
local iccfiles icc
|
||||
}
|
||||
}
|
||||
|
||||
tempvar varscore
|
||||
qui gen `varscore'=0
|
||||
label variable `varscore' "Total score"
|
||||
local scoremax=0
|
||||
local flag=0
|
||||
|
||||
if "`score'"==""&"`restscore'"==""&&"`logistic'"=="" {
|
||||
local score="score"
|
||||
}
|
||||
|
||||
local modamax=-999
|
||||
local modamin=999
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `varscore'=`varscore'+``i''
|
||||
qui su ``i''
|
||||
local modamax`i'=r(max)
|
||||
local modamin`i'=r(min)
|
||||
if r(min)!=0 {
|
||||
local flag=1
|
||||
}
|
||||
local scoremax=`scoremax'+`modamax`i''
|
||||
if `modamax`i''!=1 {
|
||||
local flagbin=0
|
||||
}
|
||||
if `modamax`i''>`modamax' {
|
||||
local modamax=`modamax`i''
|
||||
}
|
||||
if `modamin`i''<`modamin' {
|
||||
local modamin=`modamin`i''
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if `flag'==1 {
|
||||
di as error "The lower modality of the item must be 0"
|
||||
exit
|
||||
}
|
||||
*/
|
||||
if "`flagbin'"!=""&"`logistic'"!="" {
|
||||
di as error "The logistic option is not possible with polytomous items"
|
||||
exit
|
||||
}
|
||||
|
||||
qui su `varscore'
|
||||
local maxscore=r(max)
|
||||
local minscore=r(min)
|
||||
|
||||
forvalues i=`minscore'/`maxscore' {
|
||||
qui count if `varscore'>`=`i'-0.5'&`varscore'<=`=`i'+0.5'
|
||||
local nscore`i'=r(N)
|
||||
}
|
||||
|
||||
|
||||
global score
|
||||
global restscore
|
||||
global logistic
|
||||
qui count
|
||||
local N=r(N)
|
||||
if `c(matsize)'<`N'&"`saveicc'"!="" {
|
||||
set matsize `N'
|
||||
}
|
||||
|
||||
|
||||
if "`score'"!="" {
|
||||
if "`thresholds'"!="" {
|
||||
* set trace on
|
||||
local nbth:word count `thresholds'
|
||||
forvalues t=1/`nbth' {
|
||||
local th`t':word `t' of `thresholds'
|
||||
}
|
||||
tempname label
|
||||
local recode min/`th1'=1 `=`th`nbth''+1'/max=`=`nbth'+1'
|
||||
qui label define `label' 1 "min/`th1'",add
|
||||
qui label define `label' `=`nbth'+1' "`=`th`nbth''+1'/max",add
|
||||
forvalues j=2/`nbth' {
|
||||
local recode `recode' `=`th`=`j'-1''+1'/`th`j''=`j'
|
||||
qui label define `label' `j' "`=`th`=`j'-1''+1'/`th`j''",add
|
||||
}
|
||||
tempname varscore2
|
||||
qui gen `varscore2'=`varscore'
|
||||
qui recode `varscore' `recode'
|
||||
qui label values `varscore' `label'
|
||||
local nbgroups=`nbth'+1
|
||||
local minimum=1
|
||||
}
|
||||
else {
|
||||
local nbgroups=`maxscore'
|
||||
local minimum=0
|
||||
}
|
||||
local listicc
|
||||
local widthicc
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
local y`i'
|
||||
tempvar icc``i''
|
||||
gen `icc``i'''=0
|
||||
label variable `icc``i''' "``i''"
|
||||
local listicc `listicc' `icc``i'''
|
||||
local l=0
|
||||
*set trace on
|
||||
forvalues k=`=`modamin`i''+1'/`modamax`i'' {
|
||||
tempvar propscore`i'`k' tmp propscoreicc`i'`k' tmp2
|
||||
if "`cumulative'"!="" {
|
||||
qui gen `tmp'=``i''>=`k'&``i''!=.
|
||||
bysort `varscore' : egen `propscore`i'`k''=mean(`tmp')
|
||||
label variable `propscore`i'`k'' "Item ``i''>=`k'"
|
||||
}
|
||||
else {
|
||||
qui gen `tmp'=``i''==`k'&``i''!=.
|
||||
bysort `varscore' : egen `propscore`i'`k''=mean(`tmp')
|
||||
label variable `propscore`i'`k'' "Item ``i''=`k'"
|
||||
}
|
||||
if "`icc'"!="" {
|
||||
qui gen `tmp2'=``i''==`k'&``i''!=.
|
||||
bysort `varscore' : egen `propscoreicc`i'`k''=mean(`tmp2')
|
||||
qui replace `icc``i'''=`icc``i'''+`k'*`propscoreicc`i'`k''
|
||||
}
|
||||
*di "replace icc``i''=icc``i''+`k'*`propscore`i'`k''"
|
||||
local y`i'="`y`i'' `propscore`i'`k''"
|
||||
local style="solid"
|
||||
local color="black"
|
||||
local width="medthick"
|
||||
if `modamax`i''==1&"`ci'"!="" {
|
||||
tempvar icscoreminus icscoreplus
|
||||
forvalues m=1/`maxscore' {
|
||||
qui count if `varscore'==`m'
|
||||
local nscore`m'=r(N)
|
||||
}
|
||||
qui gen `icscoreminus'=`propscore`i'1'-1.96*sqrt(`propscore`i'1'*(1-`propscore`i'1')/`nscore1')
|
||||
qui gen `icscoreplus'=`propscore`i'1'+1.96*sqrt(`propscore`i'1'*(1-`propscore`i'1')/`nscore1')
|
||||
label variable `icscoreminus' "Lower 95% confidence interval"
|
||||
label variable `icscoreplus' "Upper 95% confidence interval"
|
||||
local y`i'="`icscoreminus' `icscoreplus' `propscore`i'1'"
|
||||
local style="dash dash solid"
|
||||
local color="red red black"
|
||||
local width="thin thin medthick"
|
||||
}
|
||||
if `modamax`i''==1&"`test'"!="" {
|
||||
qui regress `propscore`i'1' `varscore'
|
||||
local p=Fden(e(df_m),e(df_r),e(F))
|
||||
if `p'<0.0001 {
|
||||
local note="Test: slope=0, p<0.0001"
|
||||
}
|
||||
else {
|
||||
local p=substr("`p'",1,6)
|
||||
local note="Test: slope=0, p=`p'"
|
||||
}
|
||||
}
|
||||
local ++l
|
||||
}
|
||||
*set trace on
|
||||
if ("``i''"=="`onlyone'"|"`onlyone'"=="")&"`graph'"=="" {
|
||||
if "`filesave'"!="" {
|
||||
local saving "saving(`dirsave'//`scorefiles'_``i'',replace)"
|
||||
}
|
||||
qui graph twoway (line `y`i'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , note("`note'") ylabel(0(.25)1) xlabel(`minimum'(1)`nbgroups',valuelabel) name(score`i',replace) title("Trace of the item ``i'' as a function of the score") ytitle("Rate of positive response") `draw' `saving'
|
||||
}
|
||||
if ("``i''"=="`onlyone'"|"`onlyone'"=="")&"`icc'"!=""&"`graph'"==""{
|
||||
if "`filesave'"!="" {
|
||||
local saving "saving(`dirsave'//`iccfiles'_``i'',replace)"
|
||||
}
|
||||
local widthicc `widthicc' medthick
|
||||
qui graph twoway (line `icc``i''' `varscore', /*clpattern(`style') clcolor(`color')*/ clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , ylabel(0(.5)`modamax`i'') xlabel(`minimum'(1)`nbgroups',valuelabel) name(icc`i',replace) title("Approximate ICC of the item ``i'' as a function of the score") ytitle("Mean response") `draw' `saving'
|
||||
}
|
||||
/*
|
||||
global score "$score score`i'"
|
||||
if "`scorefiles'"!="" {
|
||||
graph save score`i' `dirsave'\\`scorefiles'``i'' ,`replace'
|
||||
}
|
||||
*/
|
||||
}
|
||||
if "`saveicc'"!="" {
|
||||
local listicc `listicc' `varscore'
|
||||
tempname matscore
|
||||
mkmat `listicc',matrix(`matscore')
|
||||
}
|
||||
if "`thresholds'"!="" {
|
||||
qui replace `varscore'=`varscore2'
|
||||
}
|
||||
if "`onlyone'"==""&"`icc'"!=""&"`graph'"=="" {
|
||||
if "`filesave'"!="" {
|
||||
local saving "saving(`dirsave'//`iccfiles',replace)"
|
||||
}
|
||||
qui graph twoway (line `listicc' `varscore', /*clpattern(`style') clcolor(`color')*/ clwidth(`widthicc')) if `varscore'!=0&`varscore'!=`maxscore' , ylabel(0(.5)`modamax`i'') xlabel(`minimum'(1)`nbgroups',valuelabel) name(icc,replace) title("Approximate ICC of the items as a function of the score") ytitle("Mean response") `draw' `saving'
|
||||
}
|
||||
}
|
||||
/*
|
||||
if "`compare'"!=""&"`graph'"=="" {
|
||||
local tmp1 : word 1 of `compare'
|
||||
local tmp2 : word 2 of `compare'
|
||||
di "compare `compare' tmp1 `tmp1' tmp2 `tmp2'"
|
||||
label variable `icc`tmp1'' `tmp1'
|
||||
label variable `icc`tmp2'' `tmp2'
|
||||
di "qui graph twoway (line `icc`tmp1'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) (line `icc`tmp2'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , ylabel(0(.5)`modamax') xlabel(`minimum'(1)`nbgroups',valuelabel) name(score`i',replace) title(Comparison of the ICC of the items `tmp1' and `tmp2') `draw' /*areastyle(none)*/"
|
||||
qui graph twoway (line `icc`tmp1'' `varscore', clpattern(`style') clcolor(blue red) clwidth(`width')) (line `icc`tmp2'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , ylabel(0(.5)`modamax') xlabel(`minimum'(1)`nbgroups',valuelabel) /*name(score`i',replace)*/ title("Comparison of the ICC of the items `tmp1' and `tmp2'") ytitle("Mean response") /*areastyle(none)*/
|
||||
}
|
||||
*/
|
||||
*set trace on
|
||||
if "`restscore'"!="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
local y`i'
|
||||
tempvar restscore`i'
|
||||
qui gen `restscore`i''=`varscore'-``i''
|
||||
label variable `restscore`i'' "Rest score with respect to the item ``i''"
|
||||
if "`thresholds'"!="" {
|
||||
* set trace on
|
||||
local nbth:word count `thresholds'
|
||||
forvalues t=1/`nbth' {
|
||||
local th`t':word `t' of `thresholds'
|
||||
}
|
||||
tempname label
|
||||
local recode 0/`th1'=1 `=`th`nbth''+1'/max=`=`nbth'+1'
|
||||
qui label define `label' 1 "min/`th1'",add
|
||||
qui label define `label' `=`nbth'+1' "`=`th`nbth''+1'/max",add
|
||||
forvalues j=2/`nbth' {
|
||||
local recode `recode' `=`th`=`j'-1''+1'/`th`j''=`j'
|
||||
qui label define `label' `j' "`=`th`=`j'-1''+1'/`th`j''",add
|
||||
}
|
||||
|
||||
*di "recode `restscore`i'' `recode'"
|
||||
qui recode `restscore`i'' `recode'
|
||||
qui label values `restscore`i'' `label'
|
||||
local nbgroups=`nbth'+1
|
||||
local minimum=1
|
||||
}
|
||||
else {
|
||||
local nbgroups=`maxscore'
|
||||
local minimum=0
|
||||
}
|
||||
|
||||
forvalues k=1/`modamax`i'' {
|
||||
tempvar rtmp proprestscore`i'`k'
|
||||
if "`cumulative'"!="" {
|
||||
qui gen `rtmp'=``i''>=`k'&``i''!=.
|
||||
bysort `restscore`i'': egen `proprestscore`i'`k''=mean(`rtmp')
|
||||
label variable `proprestscore`i'`k'' "Item ``i''>=`k'"
|
||||
}
|
||||
else {
|
||||
qui gen `rtmp'=``i''==`k'&``i''!=.
|
||||
bysort `restscore`i'': egen `proprestscore`i'`k''=mean(`rtmp')
|
||||
label variable `proprestscore`i'`k'' "Item ``i''=`k'"
|
||||
}
|
||||
local y`i'="`y`i'' `proprestscore`i'`k''"
|
||||
local style="solid"
|
||||
local color="black"
|
||||
local width="medthick"
|
||||
if `modamax`i''==1&"`ci'"!="" {
|
||||
tempvar icrestscoreminus icrestscoreplus
|
||||
qui su `restscore`i''
|
||||
local maxrestscore=r(max)
|
||||
forvalues l=1/`maxrestscore' {
|
||||
qui count if `restscore`i''==`l'
|
||||
local nrestscore`i'=r(N)
|
||||
}
|
||||
qui gen `icrestscoreminus'=`proprestscore`i'1'-1.96*sqrt(`proprestscore`i'1'*(1-`proprestscore`i'1')/`nrestscore`i'')
|
||||
qui gen `icrestscoreplus'=`proprestscore`i'1'+1.96*sqrt(`proprestscore`i'1'*(1-`proprestscore`i'1')/`nrestscore`i'')
|
||||
label variable `icrestscoreminus' "Lower 95% confidence interval"
|
||||
label variable `icrestscoreplus' "Upper 95% confidence interval"
|
||||
local y`i'="`icrestscoreminus' `icrestscoreplus' `proprestscore`i'1'"
|
||||
local style="dash dash solid"
|
||||
local color="red red black"
|
||||
local width="thin thin medthick"
|
||||
}
|
||||
if `modamax`i''==1&"`test'"!="" {
|
||||
qui regress `proprestscore`i'1' `varscore'
|
||||
local p=Fden(e(df_m),e(df_r),e(F))
|
||||
if `p'<0.0001 {
|
||||
local note="Test: slope=0, p<0.0001"
|
||||
}
|
||||
else {
|
||||
local p=substr("`p'",1,6)
|
||||
local note="Test: slope=0, p=`p'"
|
||||
}
|
||||
}
|
||||
}
|
||||
local restscoremax=`scoremax'-`modamax`i''
|
||||
if ("``i''"=="`onlyone'"|"`onlyone'"=="")&"`graph'"=="" {
|
||||
if "`filesave'"!="" {
|
||||
local saving "saving(`dirsave'//`restscorefiles'_``i'',replace)"
|
||||
}
|
||||
qui graph twoway (line `y`i'' `restscore`i'', clpattern(`style') clcolor(`color') clwidth(`width')), note("`note'") ylabel(0(0.25)1) xlabel(`minimum'(1)`nbgroups',valuelabel) name(restscore`i',replace) title("Trace of the item ``i'' as a function of the restscore") ytitle("Rate of positive response") `draw' `saving'
|
||||
}
|
||||
/*
|
||||
global restscore "$restscore restscore`i'"
|
||||
if "`restscorefiles'"!="" {
|
||||
graph save restscore`i' `dirsave'\\`restscorefiles'``i'' ,`replace'
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
if "`logistic'"!="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
qui logistic ``i'' `varscore'
|
||||
tempname coef
|
||||
matrix `coef'=e(b)
|
||||
local pente`i'=`coef'[1,1]
|
||||
local intercept`i'=`coef'[1,2]
|
||||
tempvar logit`i'
|
||||
qui gen `logit`i''=exp(`intercept`i''+`pente`i''*`varscore')/(1+exp(`intercept`i''+`pente`i''*`varscore'))
|
||||
label variable `logit`i'' "Item ``i''"
|
||||
sort `varscore'
|
||||
global logistic "$logistic `logit`i''"
|
||||
}
|
||||
}
|
||||
|
||||
if "`score'"!=""&"`onlyone'"==""&"`graph'"==""&"`drawcomb'"=="" {
|
||||
if "`filesave'"!="" {
|
||||
local saving "saving(`dirsave'//`scorefiles',replace)"
|
||||
}
|
||||
local score
|
||||
local restscoreg
|
||||
forvalues i=1/`nbitems'{
|
||||
local score `score' score`i'
|
||||
local restscoreg `restscoreg' restscore`i'
|
||||
}
|
||||
|
||||
qui graph combine `score', title("Trace of the items as a function of the score") name(score,replace) `draw' `saving'
|
||||
/*
|
||||
if "`scorefiles'"!="" {
|
||||
graph save score `dirsave'\\`scorefiles' ,`replace'
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if "`restscore'"!=""&"`onlyone'"==""&"`graph'"==""&"`drawcomb'"=="" {
|
||||
if "`filesave'"!="" {
|
||||
local saving "saving(`dirsave'//`restscorefiles',replace)"
|
||||
}
|
||||
qui graph combine `restscoreg' , title("Trace of the items as a function of the restscores") name(restscore,replace) `draw' `saving'
|
||||
/*
|
||||
if "`restscorefiles'"!="" {
|
||||
graph save restscore `dirsave'\\`restscorefiles' ,`replace'
|
||||
}
|
||||
*/
|
||||
}
|
||||
if "`logistic'"!=""&"`onlyone'"==""&"`graph'"=="" {
|
||||
if "`filesave'"!="" {
|
||||
local saving "saving(`dirsave'//`logisticfile',replace)"
|
||||
}
|
||||
qui graph twoway (line $logistic `varscore'), ylabel(0(0.25)1) xlabel(0(1)`nbitems') title("Logistic traces") ytitle("") name(logistic,replace) `draw'
|
||||
/*
|
||||
if "`logisticfile'"!="" {
|
||||
graph save logistic `dirsave'\\`logisticfile' ,`replace'
|
||||
}
|
||||
*/
|
||||
}
|
||||
if "`saveicc'"!="" {
|
||||
return matrix matscore=`matscore'
|
||||
}
|
||||
end
|
||||
|
||||
|
99
Modules/ado/personal/t/traces.hlp
Normal file
99
Modules/ado/personal/t/traces.hlp
Normal file
@ -0,0 +1,99 @@
|
||||
{smcl}
|
||||
{* 6May2013}{...}
|
||||
{hline}
|
||||
help for {hi:traces}{right:Jean-Benoit Hardouin}
|
||||
{hline}
|
||||
|
||||
{title:Graphical representations of the traces of dichotomous and polytomous items}
|
||||
|
||||
{p 8 14 2}{cmd:traces} {it:varlist} [{cmd:,} {cmdab:s:core} {cmdab:r:estscore}
|
||||
{cmdab:ci} {cmdab:t:est} {cmdab:cum:ulative} {cmdab:l:ogistic}
|
||||
{cmdab:repf:ile}({it:directory}) {cmdab:scoref:iles}({it:string})
|
||||
{cmdab:restscoref:iles}({it:string}) {cmdab:logisticf:ile}({it:string})
|
||||
{cmdab:nod:raw} {cmdab:nodrawc:omb} {cmdab:rep:lace} {cmdab:only:one}({it:varname}) {cmdab:thr:esholds}({it:string})]
|
||||
|
||||
|
||||
{title:Description}
|
||||
|
||||
{p 4 8 2}{cmd:traces} builds graphical representations of various kinds of
|
||||
traces (non parametric Item Response Functions) for dichotomous or polytomous items.
|
||||
|
||||
{title:Options}
|
||||
|
||||
{p 4 8 2}{cmd:score} displays the graphical representations of the traces of the
|
||||
items as a function of the total score. This is the defaut option if none {cmd:score},
|
||||
none {cmd:restscore}, none {cmd:logistic} are indicated.
|
||||
|
||||
{p 4 8 2}{cmd:restscore} displays the graphical representations of the
|
||||
traces of the items as a function of the rest-score (total score unless the item).
|
||||
|
||||
{p 4 8 2}{cmd:ci} displays the confidence interval at 95% of the traces.
|
||||
|
||||
{p 4 8 2}{cmd:test} tests the nullity of the slope of dichotomous items traces
|
||||
with a linear model.
|
||||
|
||||
{p 4 8 2}{cmd:cumulative} displays cumulative traces for polytomous
|
||||
items instead of classical traces.
|
||||
|
||||
{p 4 8 2}{cmd:logistic} displays the graphical representation of the logitic
|
||||
traces of the items as a function of the score: each trace is the result of a
|
||||
logistic model with the response to the item as variable to explicate and the
|
||||
score (and a constant) as explicative variable. This kind of trace is possible
|
||||
only for dichotomous items. All the logistic traces are represented in the same
|
||||
graph.
|
||||
|
||||
{p 4 8 2}{cmd:repfile}({it:directory}) is the directory where the files are saved.
|
||||
|
||||
{p 4 8 2}{cmd:scorefiles}({it:string}) defines the generic name of the files containing the graphical representations of the traces as a function of the score.
|
||||
The name will be followed by the name of each item and by the .gph extension. If this option is not
|
||||
indicated, the corresponding graphs will be not saved.
|
||||
|
||||
{p 4 8 2}{cmd:restscorefiles}({it:string}) defines the generic name of the files containing the graphical representations of the traces as a function of the rest-scores.
|
||||
The name will be followed by the name of each item and by the .gph extension. If this option is not
|
||||
indicated, the corresponding graphs will be not saved.
|
||||
|
||||
{p 4 8 2}{cmd:logisticfile}({it:string}) defines the name of the file containing the graphical representations of the logistic traces. This name will be followed by the .gph extension.
|
||||
If this option is not indicated, the corresponding graph will be not saved.
|
||||
|
||||
{p 4 8 2}{cmd:nodraw} does not display the graphs by items.
|
||||
|
||||
{p 4 8 2}{cmd:nodrawcomb} does not display the combined graphs by items.
|
||||
|
||||
{p 4 8 2}{cmd:replace} replaces graphical files when they already exist.
|
||||
|
||||
{p 4 8 2}{cmd:onlyone} displays only the trace of a given item.
|
||||
|
||||
{p 4 8 2}{cmd:thresholds} groups the individuals as a function of the (rest-)score. The string contains the maximal values of the (rest-)score in each group.
|
||||
|
||||
|
||||
|
||||
{title:Example}
|
||||
|
||||
{p 4 8 2}{cmd:. traces item1 item2 item3 item4 , score repfile(c:\graphs) scorefiles(score) nodraw nodrawcomb replace} /*creates the graphs files of the
|
||||
traces as a function of the score but do not display them.*/
|
||||
|
||||
{p 4 8 2}{cmd:. traces item1 item2 item3 item4 , score restscore} /*displays
|
||||
the graphical representations of the traces of the items as a function of the
|
||||
score and of the rest-scores, but does not save them*/
|
||||
|
||||
{p 4 8 2}{cmd:. traces itemA*} /*displays the graphical
|
||||
representations of the traces of the items as a function of the score, by
|
||||
default*/
|
||||
|
||||
{p 4 8 2}{cmd:. traces itemA*} ,only(itemA2) thresholds(2 3 5)/*displays the graphical
|
||||
representations of the traces of the item A2 as a function of the score. Individuals are grouped: a first group of individuals with scores from 0 to 2, a second group with a score of 3, a third group with a score between 4 and 5 and a last group with a score superior to 5*/
|
||||
|
||||
{title:Author}
|
||||
|
||||
{p 4 8 2}Jean-Benoit Hardouin, PhD, assistant professor{p_end}
|
||||
{p 4 8 2}Team of Biostatistics, Clinical Research and Subjective Measures in Health Sciences{p_end}
|
||||
{p 4 8 2}University of Nantes - Faculty of Pharmaceutical Sciences{p_end}
|
||||
{p 4 8 2}1, rue Gaston Veil - BP 53508{p_end}
|
||||
{p 4 8 2}44035 Nantes Cedex 1 - FRANCE{p_end}
|
||||
{p 4 8 2}Email:
|
||||
{browse "mailto:jean-benoit.hardouin@univ-nantes.fr":jean-benoit.hardouin@univ-nantes.fr}{p_end}
|
||||
{p 4 8 2}Website {browse "http://www.anaqol.org":AnaQol}
|
||||
|
||||
{title:Also see}
|
||||
|
||||
{p 4 13 2}Online: help for {help graph}, {help loevH} and {help gengroup} if installed.{p_end}
|
232
Modules/ado/personal/t/traces3.ado
Normal file
232
Modules/ado/personal/t/traces3.ado
Normal file
@ -0,0 +1,232 @@
|
||||
************************************************************************************************************
|
||||
* Traces: Traces of items
|
||||
* version 3: July 9, 2003
|
||||
*
|
||||
* Historic:
|
||||
* Version 1 (2003-06-29): Jean-Benoit Hardouin
|
||||
* Version 2 (2003-07-04): Jean-Benoit Hardouin
|
||||
*
|
||||
* 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 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 traces
|
||||
version 8.0
|
||||
syntax varlist(numeric min=2) [, score test restscore logistic ci cumulative repfiles(string) scorefiles(string) restscorefiles(string) logisticfile(string) nodraw nodrawcomb replace]
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
tempvar varscore
|
||||
gen `varscore'=0
|
||||
label variable `varscore' "Total score"
|
||||
local scoremax=0
|
||||
local flag=0
|
||||
|
||||
if "`score'"==""&"`restscore'"==""&&"`logistic'"=="" {
|
||||
local score="score"
|
||||
}
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `varscore'=`varscore'+``i''
|
||||
qui su ``i''
|
||||
local modamax`i'=r(max)
|
||||
if r(min)!=0 {
|
||||
local flag=1
|
||||
}
|
||||
local scoremax=`scoremax'+`modamax`i''
|
||||
if `modamax`i''!=1 {
|
||||
local flagbin=0
|
||||
}
|
||||
}
|
||||
|
||||
if `flag'==1 {
|
||||
di as error "The lower modalities of the item must be 0"
|
||||
exit
|
||||
}
|
||||
|
||||
qui su `varscore'
|
||||
local maxscore=r(max)
|
||||
|
||||
forvalues i=0/`maxscore' {
|
||||
qui count if `varscore'==`i'
|
||||
local nscore`i'=r(N)
|
||||
}
|
||||
|
||||
if "`flagbin'"!=""&"`logistic'"!="" {
|
||||
di as error "The logistic option is impossible with polytomic items"
|
||||
exit
|
||||
}
|
||||
|
||||
global score
|
||||
global restscore
|
||||
global logistic
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
if "`score'"!="" {
|
||||
local y`i'
|
||||
forvalues k=1/`modamax`i'' {
|
||||
tempvar propscore`i'`k' tmp
|
||||
if "`cumulative'"!="" {
|
||||
gen `tmp'=``i''>=`k'
|
||||
bysort `varscore' : egen `propscore`i'`k''=mean(`tmp')
|
||||
label variable `propscore`i'`k'' "Item ``i''>=`k'"
|
||||
}
|
||||
else {
|
||||
gen `tmp'=``i''==`k'
|
||||
bysort `varscore' : egen `propscore`i'`k''=mean(`tmp')
|
||||
label variable `propscore`i'`k'' "Item ``i''=`k'"
|
||||
}
|
||||
local y`i'="`y`i'' `propscore`i'`k''"
|
||||
local style="solid"
|
||||
local color="black"
|
||||
local width="medthick"
|
||||
if `modamax`i''==1&"`ci'"!="" {
|
||||
tempvar icscoreminus icscoreplus
|
||||
gen `icscoreminus'=`propscore`i'1'-1.96*sqrt(`propscore`i'1'*(1-`propscore`i'1')/`nscore`i'')
|
||||
gen `icscoreplus'=`propscore`i'1'+1.96*sqrt(`propscore`i'1'*(1-`propscore`i'1')/`nscore`i'')
|
||||
label variable `icscoreminus' "Lower 95% confidence interval"
|
||||
label variable `icscoreplus' "Upper 95% confidence interval"
|
||||
local y`i'="`icscoreminus' `icscoreplus' `propscore`i'1'"
|
||||
local style="dash dash solid"
|
||||
local color="red red black"
|
||||
local width="thin thin medthick"
|
||||
}
|
||||
if `modamax`i''==1&"`test'"!="" {
|
||||
qui regress `propscore`i'1' `varscore'
|
||||
local p=Fden(e(df_m),e(df_r),e(F))
|
||||
if `p'<0.0001 {
|
||||
local note="Test: slope=0, p<0.0001"
|
||||
}
|
||||
else {
|
||||
local p=substr("`p'",1,6)
|
||||
local note="Test: slope=0, p=`p'"
|
||||
}
|
||||
}
|
||||
}
|
||||
qui graph twoway (line `y`i'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , note("`note'") ylabel(0(.25)1) xlabel(0(1)`scoremax') name(score`i',replace) title("Trace of the item ``i'' in fonction of the score") ytitle("Rate of positive response") `draw'
|
||||
global score "$score score`i'"
|
||||
if "`scorefiles'"!="" {
|
||||
graph save score`i' `repfiles'\\`scorefiles'``i'' ,`replace'
|
||||
}
|
||||
}
|
||||
if "`restscore'"!="" {
|
||||
local y`i'
|
||||
tempvar restscore`i'
|
||||
gen `restscore`i''=`varscore'-``i''
|
||||
label variable `restscore`i'' "Rest score with respect to the item ``i''"
|
||||
forvalues k=1/`modamax`i'' {
|
||||
tempvar rtmp proprestscore`i'`k'
|
||||
if "`cumulative'"!="" {
|
||||
gen `rtmp'=``i''>=`k'
|
||||
bysort `restscore`i'': egen `proprestscore`i'`k''=mean(`rtmp')
|
||||
label variable `proprestscore`i'`k'' "Item ``i''>=`k'"
|
||||
}
|
||||
else {
|
||||
gen `rtmp'=``i''==`k'
|
||||
bysort `restscore`i'': egen `proprestscore`i'`k''=mean(`rtmp')
|
||||
label variable `proprestscore`i'`k'' "Item ``i''=`k'"
|
||||
}
|
||||
local y`i'="`y`i'' `proprestscore`i'`k''"
|
||||
local style="solid"
|
||||
local color="black"
|
||||
local width="medthick"
|
||||
if `modamax`i''==1&"`ci'"!="" {
|
||||
tempvar icrestscoreminus icrestscoreplus
|
||||
qui su `restscore`i''
|
||||
local maxrestscore=r(max)
|
||||
forvalues l=1/`maxrestscore' {
|
||||
qui count if `restscore`i''==`l'
|
||||
local nrestscore`i'=r(N)
|
||||
}
|
||||
gen `icrestscoreminus'=`proprestscore`i'1'-1.96*sqrt(`proprestscore`i'1'*(1-`proprestscore`i'1')/`nrestscore`i'')
|
||||
gen `icrestscoreplus'=`proprestscore`i'1'+1.96*sqrt(`proprestscore`i'1'*(1-`proprestscore`i'1')/`nrestscore`i'')
|
||||
label variable `icrestscoreminus' "Lower 95% confidence interval"
|
||||
label variable `icrestscoreplus' "Upper 95% confidence interval"
|
||||
local y`i'="`icrestscoreminus' `icrestscoreplus' `proprestscore`i'1'"
|
||||
local style="dash dash solid"
|
||||
local color="red red black"
|
||||
local width="thin thin medthick"
|
||||
}
|
||||
if `modamax`i''==1&"`test'"!="" {
|
||||
qui regress `proprestscore`i'1' `varscore'
|
||||
local p=Fden(e(df_m),e(df_r),e(F))
|
||||
if `p'<0.0001 {
|
||||
local note="Test: slope=0, p<0.0001"
|
||||
}
|
||||
else {
|
||||
local p=substr("`p'",1,6)
|
||||
local note="Test: slope=0, p=`p'"
|
||||
}
|
||||
}
|
||||
}
|
||||
local restscoremax=`scoremax'-`modamax`i''
|
||||
qui graph twoway (line `y`i'' `restscore`i'', clpattern(`style') clcolor(`color') clwidth(`width')), note("`note'") ylabel(0(0.25)1) xlabel(0(1)`restscoremax') name(restscore`i',replace) title("Trace of the item ``i'' in fonction of the restscore") ytitle("Rate of positive response") `draw'
|
||||
global restscore "$restscore restscore`i'"
|
||||
if "`restscorefiles'"!="" {
|
||||
graph save restscore`i' `repfiles'\\`restscorefiles'``i'' ,`replace'
|
||||
}
|
||||
}
|
||||
if "logistic"!="" {
|
||||
qui logistic ``i'' `varscore'
|
||||
tempname coef
|
||||
matrix `coef'=e(b)
|
||||
local pente`i'=`coef'[1,1]
|
||||
local intercept`i'=`coef'[1,2]
|
||||
tempvar logit`i'
|
||||
gen `logit`i''=exp(`intercept`i''+`pente`i''*`varscore')/(1+exp(`intercept`i''+`pente`i''*`varscore'))
|
||||
label variable `logit`i'' "Item ``i''"
|
||||
sort `varscore'
|
||||
global logistic "$logistic `logit`i''"
|
||||
}
|
||||
}
|
||||
|
||||
if "`drawcomb'"!="" {
|
||||
local drawcomb="nodraw"
|
||||
}
|
||||
|
||||
if "`score'"!="" {
|
||||
graph combine $score , title("Trace of the items in function of the score") name(score,replace) `drawcomb'
|
||||
if "`scorefiles'"!="" {
|
||||
graph save score `repfiles'\\`scorefiles' ,`replace'
|
||||
}
|
||||
}
|
||||
|
||||
if "`restscore'"!="" {
|
||||
graph combine $restscore , title("Trace of the items in function of the restscores") name(restscore,replace) `drawcomb'
|
||||
if "`restscorefiles'"!="" {
|
||||
graph save restscore `repfiles'\\`restscorefiles' ,`replace'
|
||||
}
|
||||
}
|
||||
|
||||
if "`logistic'"!="" {
|
||||
graph twoway (line $logistic `varscore'), ylabel(0(0.25)1) xlabel(0(1)`nbitems') title("Logistic traces") ytitle("") name(logistic,replace) `drawcomb'
|
||||
if "`logisticfile'"!="" {
|
||||
graph save logistic `repfiles'\\`logisticfile' ,`replace'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
309
Modules/ado/personal/t/traces32.ado
Normal file
309
Modules/ado/personal/t/traces32.ado
Normal file
@ -0,0 +1,309 @@
|
||||
*! Version 3.2 27May2007
|
||||
************************************************************************************************************
|
||||
* Traces: Traces of items
|
||||
* Version 3.2: May 27, 2007 (onlyone option)
|
||||
*
|
||||
* Historic:
|
||||
* Version 1 (2003-06-29): Jean-Benoit Hardouin
|
||||
* Version 2 (2003-07-04): Jean-Benoit Hardouin
|
||||
* version 3 (2003-07-09): Jean-Benoit Hardouin
|
||||
* Version 3.1 (2005-06-07): Jean-Benoit Hardouin /*small modifications*/
|
||||
*
|
||||
* Jean-benoit Hardouin, phD, Assistant Professor
|
||||
* Team of Biostatistics, Clinical Research and Subjective Measures in Health Sciences
|
||||
* University of Nantes - Faculty of Pharmaceutical Sciences
|
||||
* France
|
||||
* jean-benoit.hardouin@anaqol.org
|
||||
*
|
||||
* News about this program :http://www.anaqol.org
|
||||
* FreeIRT Project website : http://www.freeirt.org
|
||||
*
|
||||
* Copyright 2003, 2005, 2007 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 traces
|
||||
version 8.0
|
||||
syntax varlist(numeric min=2) [, Score Test Restscore Logistic CI CUMulative REPFiles(string) SCOREFiles(string) RESTSCOREFiles(string) LOGISTICFile(string) noDraw noDRAWComb REPlace ONLYone(string) THResholds(string)]
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
if "`onlyone'"!=""&"`drawcomb'"!="" {
|
||||
local drawcomb
|
||||
}
|
||||
|
||||
tempvar varscore
|
||||
qui gen `varscore'=0
|
||||
label variable `varscore' "Total score"
|
||||
local scoremax=0
|
||||
local flag=0
|
||||
|
||||
if "`score'"==""&"`restscore'"==""&&"`logistic'"=="" {
|
||||
local score="score"
|
||||
}
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `varscore'=`varscore'+``i''
|
||||
qui su ``i''
|
||||
local modamax`i'=r(max)
|
||||
if r(min)!=0 {
|
||||
local flag=1
|
||||
}
|
||||
local scoremax=`scoremax'+`modamax`i''
|
||||
if `modamax`i''!=1 {
|
||||
local flagbin=0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if `flag'==1 {
|
||||
di as error "The lower modality of the item must be 0"
|
||||
exit
|
||||
}
|
||||
if "`flagbin'"!=""&"`logistic'"!="" {
|
||||
di as error "The logistic option is not possible with polytomous items"
|
||||
exit
|
||||
}
|
||||
|
||||
qui su `varscore'
|
||||
local maxscore=r(max)
|
||||
|
||||
forvalues i=0/`maxscore' {
|
||||
qui count if `varscore'==`i'
|
||||
local nscore`i'=r(N)
|
||||
}
|
||||
|
||||
|
||||
global score
|
||||
global restscore
|
||||
global logistic
|
||||
|
||||
if "`score'"!="" {
|
||||
if "`thresholds'"!="" {
|
||||
* set trace on
|
||||
local nbth:word count `thresholds'
|
||||
forvalues t=1/`nbth' {
|
||||
local th`t':word `t' of `thresholds'
|
||||
}
|
||||
tempname label
|
||||
local recode 0/`th1'=1 `=`th`nbth''+1'/max=`=`nbth'+1'
|
||||
qui label define `label' 1 "0/`th1'",add
|
||||
qui label define `label' `=`nbth'+1' "`=`th`nbth''+1'/max",add
|
||||
forvalues j=2/`nbth' {
|
||||
local recode `recode' `=`th`=`j'-1''+1'/`th`j''=`j'
|
||||
qui label define `label' `j' "`=`th`=`j'-1''+1'/`th`j''",add
|
||||
}
|
||||
tempname varscore2
|
||||
qui gen `varscore2'=`varscore'
|
||||
qui recode `varscore' `recode'
|
||||
qui label values `varscore' `label'
|
||||
local nbgroups=`nbth'+1
|
||||
local minimum=1
|
||||
}
|
||||
else {
|
||||
local nbgroups=`maxscore'
|
||||
local minimum=0
|
||||
}
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
local y`i'
|
||||
forvalues k=1/`modamax`i'' {
|
||||
tempvar propscore`i'`k' tmp
|
||||
if "`cumulative'"!="" {
|
||||
qui gen `tmp'=``i''>=`k'&``i''!=.
|
||||
bysort `varscore' : egen `propscore`i'`k''=mean(`tmp')
|
||||
label variable `propscore`i'`k'' "Item ``i''>=`k'"
|
||||
}
|
||||
else {
|
||||
qui gen `tmp'=``i''==`k'&``i''!=.
|
||||
bysort `varscore' : egen `propscore`i'`k''=mean(`tmp')
|
||||
label variable `propscore`i'`k'' "Item ``i''=`k'"
|
||||
}
|
||||
local y`i'="`y`i'' `propscore`i'`k''"
|
||||
local style="solid"
|
||||
local color="black"
|
||||
local width="medthick"
|
||||
if `modamax`i''==1&"`ci'"!="" {
|
||||
tempvar icscoreminus icscoreplus
|
||||
forvalues l=1/`maxscore' {
|
||||
qui count if `varscore'==`l'
|
||||
local nscore`l'=r(N)
|
||||
}
|
||||
qui gen `icscoreminus'=`propscore`i'1'-1.96*sqrt(`propscore`i'1'*(1-`propscore`i'1')/`nscore1')
|
||||
qui gen `icscoreplus'=`propscore`i'1'+1.96*sqrt(`propscore`i'1'*(1-`propscore`i'1')/`nscore1')
|
||||
label variable `icscoreminus' "Lower 95% confidence interval"
|
||||
label variable `icscoreplus' "Upper 95% confidence interval"
|
||||
local y`i'="`icscoreminus' `icscoreplus' `propscore`i'1'"
|
||||
local style="dash dash solid"
|
||||
local color="red red black"
|
||||
local width="thin thin medthick"
|
||||
}
|
||||
if `modamax`i''==1&"`test'"!="" {
|
||||
qui regress `propscore`i'1' `varscore'
|
||||
local p=Fden(e(df_m),e(df_r),e(F))
|
||||
if `p'<0.0001 {
|
||||
local note="Test: slope=0, p<0.0001"
|
||||
}
|
||||
else {
|
||||
local p=substr("`p'",1,6)
|
||||
local note="Test: slope=0, p=`p'"
|
||||
}
|
||||
}
|
||||
}
|
||||
if "``i''"=="`onlyone'"|"`onlyone'"=="" {
|
||||
qui graph twoway (line `y`i'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , note("`note'") ylabel(0(.25)1) xlabel(`minimum'(1)`nbgroups',valuelabel) name(score`i',replace) title("Trace of the item ``i'' as a function of the score") ytitle("Rate of positive response") `draw'
|
||||
}
|
||||
global score "$score score`i'"
|
||||
if "`scorefiles'"!="" {
|
||||
graph save score`i' `repfiles'\\`scorefiles'``i'' ,`replace'
|
||||
}
|
||||
}
|
||||
if "`thresholds'"!="" {
|
||||
qui replace `varscore'=`varscore2'
|
||||
}
|
||||
}
|
||||
if "`restscore'"!="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
local y`i'
|
||||
tempvar restscore`i'
|
||||
qui gen `restscore`i''=`varscore'-``i''
|
||||
label variable `restscore`i'' "Rest score with respect to the item ``i''"
|
||||
if "`thresholds'"!="" {
|
||||
* set trace on
|
||||
local nbth:word count `thresholds'
|
||||
forvalues t=1/`nbth' {
|
||||
local th`t':word `t' of `thresholds'
|
||||
}
|
||||
tempname label
|
||||
local recode 0/`th1'=1 `=`th`nbth''+1'/max=`=`nbth'+1'
|
||||
qui label define `label' 1 "0/`th1'",add
|
||||
qui label define `label' `=`nbth'+1' "`=`th`nbth''+1'/max",add
|
||||
forvalues j=2/`nbth' {
|
||||
local recode `recode' `=`th`=`j'-1''+1'/`th`j''=`j'
|
||||
qui label define `label' `j' "`=`th`=`j'-1''+1'/`th`j''",add
|
||||
}
|
||||
|
||||
*di "recode `restscore`i'' `recode'"
|
||||
qui recode `restscore`i'' `recode'
|
||||
qui label values `restscore`i'' `label'
|
||||
local nbgroups=`nbth'+1
|
||||
local minimum=1
|
||||
}
|
||||
else {
|
||||
local nbgroups=`maxscore'
|
||||
local minimum=0
|
||||
}
|
||||
|
||||
forvalues k=1/`modamax`i'' {
|
||||
tempvar rtmp proprestscore`i'`k'
|
||||
if "`cumulative'"!="" {
|
||||
qui gen `rtmp'=``i''>=`k'&``i''!=.
|
||||
bysort `restscore`i'': egen `proprestscore`i'`k''=mean(`rtmp')
|
||||
label variable `proprestscore`i'`k'' "Item ``i''>=`k'"
|
||||
}
|
||||
else {
|
||||
qui gen `rtmp'=``i''==`k'&``i''!=.
|
||||
bysort `restscore`i'': egen `proprestscore`i'`k''=mean(`rtmp')
|
||||
label variable `proprestscore`i'`k'' "Item ``i''=`k'"
|
||||
}
|
||||
local y`i'="`y`i'' `proprestscore`i'`k''"
|
||||
local style="solid"
|
||||
local color="black"
|
||||
local width="medthick"
|
||||
if `modamax`i''==1&"`ci'"!="" {
|
||||
tempvar icrestscoreminus icrestscoreplus
|
||||
qui su `restscore`i''
|
||||
local maxrestscore=r(max)
|
||||
forvalues l=1/`maxrestscore' {
|
||||
qui count if `restscore`i''==`l'
|
||||
local nrestscore`i'=r(N)
|
||||
}
|
||||
qui gen `icrestscoreminus'=`proprestscore`i'1'-1.96*sqrt(`proprestscore`i'1'*(1-`proprestscore`i'1')/`nrestscore`i'')
|
||||
qui gen `icrestscoreplus'=`proprestscore`i'1'+1.96*sqrt(`proprestscore`i'1'*(1-`proprestscore`i'1')/`nrestscore`i'')
|
||||
label variable `icrestscoreminus' "Lower 95% confidence interval"
|
||||
label variable `icrestscoreplus' "Upper 95% confidence interval"
|
||||
local y`i'="`icrestscoreminus' `icrestscoreplus' `proprestscore`i'1'"
|
||||
local style="dash dash solid"
|
||||
local color="red red black"
|
||||
local width="thin thin medthick"
|
||||
}
|
||||
if `modamax`i''==1&"`test'"!="" {
|
||||
qui regress `proprestscore`i'1' `varscore'
|
||||
local p=Fden(e(df_m),e(df_r),e(F))
|
||||
if `p'<0.0001 {
|
||||
local note="Test: slope=0, p<0.0001"
|
||||
}
|
||||
else {
|
||||
local p=substr("`p'",1,6)
|
||||
local note="Test: slope=0, p=`p'"
|
||||
}
|
||||
}
|
||||
}
|
||||
local restscoremax=`scoremax'-`modamax`i''
|
||||
if "``i''"=="`onlyone'"|"`onlyone'"=="" {
|
||||
*tab `proprestscore`i'1' `restscore`i''
|
||||
qui graph twoway (line `y`i'' `restscore`i'', clpattern(`style') clcolor(`color') clwidth(`width')), note("`note'") ylabel(0(0.25)1) xlabel(`minimum'(1)`nbgroups',valuelabel) name(restscore`i',replace) title("Trace of the item ``i'' as a function of the restscore") ytitle("Rate of positive response") `draw'
|
||||
}
|
||||
global restscore "$restscore restscore`i'"
|
||||
if "`restscorefiles'"!="" {
|
||||
graph save restscore`i' `repfiles'\\`restscorefiles'``i'' ,`replace'
|
||||
}
|
||||
}
|
||||
}
|
||||
if "logistic"!="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
qui logistic ``i'' `varscore'
|
||||
tempname coef
|
||||
matrix `coef'=e(b)
|
||||
local pente`i'=`coef'[1,1]
|
||||
local intercept`i'=`coef'[1,2]
|
||||
tempvar logit`i'
|
||||
qui gen `logit`i''=exp(`intercept`i''+`pente`i''*`varscore')/(1+exp(`intercept`i''+`pente`i''*`varscore'))
|
||||
label variable `logit`i'' "Item ``i''"
|
||||
sort `varscore'
|
||||
global logistic "$logistic `logit`i''"
|
||||
}
|
||||
}
|
||||
if "`drawcomb'"!="" {
|
||||
local drawcomb="nodraw"
|
||||
}
|
||||
|
||||
if "`score'"!=""&"`onlyone'"=="" {
|
||||
graph combine $score , title("Trace of the items as a function of the score") name(score,replace) `drawcomb'
|
||||
if "`scorefiles'"!="" {
|
||||
graph save score `repfiles'\\`scorefiles' ,`replace'
|
||||
}
|
||||
}
|
||||
|
||||
if "`restscore'"!=""&"`onlyone'"=="" {
|
||||
graph combine $restscore , title("Trace of the items as a function of the restscores") name(restscore,replace) `drawcomb'
|
||||
if "`restscorefiles'"!="" {
|
||||
graph save restscore `repfiles'\\`restscorefiles' ,`replace'
|
||||
}
|
||||
}
|
||||
if "`logistic'"!="" {
|
||||
graph twoway (line $logistic `varscore'), ylabel(0(0.25)1) xlabel(0(1)`nbitems') title("Logistic traces") ytitle("") name(logistic,replace) `drawcomb'
|
||||
if "`logisticfile'"!="" {
|
||||
graph save logistic `repfiles'\\`logisticfile' ,`replace'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
310
Modules/ado/personal/t/traces33.ado
Normal file
310
Modules/ado/personal/t/traces33.ado
Normal file
@ -0,0 +1,310 @@
|
||||
*! Version 3.3 16October2012
|
||||
************************************************************************************************************
|
||||
* Traces: Traces of items
|
||||
* Version 3.3: October 16, 2012 /*minor modifications*/
|
||||
*
|
||||
* Historic:
|
||||
* Version 1 (2003-06-29): Jean-Benoit Hardouin
|
||||
* Version 2 (2003-07-04): Jean-Benoit Hardouin
|
||||
* version 3 (2003-07-09): Jean-Benoit Hardouin
|
||||
* Version 3.1 (2005-06-07): Jean-Benoit Hardouin /*small modifications*/
|
||||
* Version 3.2: May 27, 2007 /*onlyone option*/
|
||||
*
|
||||
* Jean-benoit Hardouin, phD, Assistant Professor
|
||||
* Team of Biostatistics, Clinical Research and Subjective Measures in Health Sciences
|
||||
* University of Nantes - Faculty of Pharmaceutical Sciences
|
||||
* France
|
||||
* jean-benoit.hardouin@anaqol.org
|
||||
*
|
||||
* News about this program :http://www.anaqol.org
|
||||
* FreeIRT Project website : http://www.freeirt.org
|
||||
*
|
||||
* Copyright 2003, 2005, 2007, 2012 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 traces
|
||||
version 8.0
|
||||
syntax varlist(numeric min=2) [, Score Test Restscore Logistic CI CUMulative REPFiles(string) SCOREFiles(string) RESTSCOREFiles(string) LOGISTICFile(string) noDraw noDRAWComb REPlace ONLYone(string) THResholds(string) Black]
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
if "`onlyone'"!=""&"`drawcomb'"!="" {
|
||||
local drawcomb
|
||||
}
|
||||
|
||||
tempvar varscore
|
||||
qui gen `varscore'=0
|
||||
label variable `varscore' "Total score"
|
||||
local scoremax=0
|
||||
local flag=0
|
||||
|
||||
if "`score'"==""&"`restscore'"==""&&"`logistic'"=="" {
|
||||
local score="score"
|
||||
}
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `varscore'=`varscore'+``i''
|
||||
qui su ``i''
|
||||
local modamax`i'=r(max)
|
||||
if r(min)!=0 {
|
||||
local flag=1
|
||||
}
|
||||
local scoremax=`scoremax'+`modamax`i''
|
||||
if `modamax`i''!=1 {
|
||||
local flagbin=0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if `flag'==1 {
|
||||
di as error "The lower modality of the item must be 0"
|
||||
exit
|
||||
}
|
||||
if "`flagbin'"!=""&"`logistic'"!="" {
|
||||
di as error "The logistic option is not possible with polytomous items"
|
||||
exit
|
||||
}
|
||||
|
||||
qui su `varscore'
|
||||
local maxscore=r(max)
|
||||
|
||||
forvalues i=0/`maxscore' {
|
||||
qui count if `varscore'==`i'
|
||||
local nscore`i'=r(N)
|
||||
}
|
||||
|
||||
|
||||
global score
|
||||
global restscore
|
||||
global logistic
|
||||
|
||||
if "`score'"!="" {
|
||||
if "`thresholds'"!="" {
|
||||
* set trace on
|
||||
local nbth:word count `thresholds'
|
||||
forvalues t=1/`nbth' {
|
||||
local th`t':word `t' of `thresholds'
|
||||
}
|
||||
tempname label
|
||||
local recode 0/`th1'=1 `=`th`nbth''+1'/max=`=`nbth'+1'
|
||||
qui label define `label' 1 "0/`th1'",add
|
||||
qui label define `label' `=`nbth'+1' "`=`th`nbth''+1'/max",add
|
||||
forvalues j=2/`nbth' {
|
||||
local recode `recode' `=`th`=`j'-1''+1'/`th`j''=`j'
|
||||
qui label define `label' `j' "`=`th`=`j'-1''+1'/`th`j''",add
|
||||
}
|
||||
tempname varscore2
|
||||
qui gen `varscore2'=`varscore'
|
||||
qui recode `varscore' `recode'
|
||||
qui label values `varscore' `label'
|
||||
local nbgroups=`nbth'+1
|
||||
local minimum=1
|
||||
}
|
||||
else {
|
||||
local nbgroups=`maxscore'
|
||||
local minimum=0
|
||||
}
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
local y`i'
|
||||
forvalues k=1/`modamax`i'' {
|
||||
tempvar propscore`i'`k' tmp
|
||||
if "`cumulative'"!="" {
|
||||
qui gen `tmp'=``i''>=`k'&``i''!=.
|
||||
bysort `varscore' : egen `propscore`i'`k''=mean(`tmp')
|
||||
label variable `propscore`i'`k'' "Item ``i''>=`k'"
|
||||
}
|
||||
else {
|
||||
qui gen `tmp'=``i''==`k'&``i''!=.
|
||||
bysort `varscore' : egen `propscore`i'`k''=mean(`tmp')
|
||||
label variable `propscore`i'`k'' "Item ``i''=`k'"
|
||||
}
|
||||
local y`i'="`y`i'' `propscore`i'`k''"
|
||||
local style="solid"
|
||||
local color="black"
|
||||
local width="medthick"
|
||||
if `modamax`i''==1&"`ci'"!="" {
|
||||
tempvar icscoreminus icscoreplus
|
||||
forvalues l=1/`maxscore' {
|
||||
qui count if `varscore'==`l'
|
||||
local nscore`l'=r(N)
|
||||
}
|
||||
qui gen `icscoreminus'=`propscore`i'1'-1.96*sqrt(`propscore`i'1'*(1-`propscore`i'1')/`nscore1')
|
||||
qui gen `icscoreplus'=`propscore`i'1'+1.96*sqrt(`propscore`i'1'*(1-`propscore`i'1')/`nscore1')
|
||||
label variable `icscoreminus' "Lower 95% confidence interval"
|
||||
label variable `icscoreplus' "Upper 95% confidence interval"
|
||||
local y`i'="`icscoreminus' `icscoreplus' `propscore`i'1'"
|
||||
local style="dash dash solid"
|
||||
local color="red red black"
|
||||
local width="thin thin medthick"
|
||||
}
|
||||
if `modamax`i''==1&"`test'"!="" {
|
||||
qui regress `propscore`i'1' `varscore'
|
||||
local p=Fden(e(df_m),e(df_r),e(F))
|
||||
if `p'<0.0001 {
|
||||
local note="Test: slope=0, p<0.0001"
|
||||
}
|
||||
else {
|
||||
local p=substr("`p'",1,6)
|
||||
local note="Test: slope=0, p=`p'"
|
||||
}
|
||||
}
|
||||
}
|
||||
if "``i''"=="`onlyone'"|"`onlyone'"=="" {
|
||||
qui graph twoway (line `y`i'' `varscore', clpattern(`style') clcolor(`color') clwidth(`width')) if `varscore'!=0&`varscore'!=`maxscore' , note("`note'") ylabel(0(.25)1) xlabel(`minimum'(1)`nbgroups',valuelabel) name(score`i',replace) title("Trace of the item ``i'' as a function of the score") ytitle("Rate of positive response") `draw' areastyle(none)
|
||||
}
|
||||
global score "$score score`i'"
|
||||
if "`scorefiles'"!="" {
|
||||
graph save score`i' `repfiles'\\`scorefiles'``i'' ,`replace'
|
||||
}
|
||||
}
|
||||
if "`thresholds'"!="" {
|
||||
qui replace `varscore'=`varscore2'
|
||||
}
|
||||
}
|
||||
if "`restscore'"!="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
local y`i'
|
||||
tempvar restscore`i'
|
||||
qui gen `restscore`i''=`varscore'-``i''
|
||||
label variable `restscore`i'' "Rest score with respect to the item ``i''"
|
||||
if "`thresholds'"!="" {
|
||||
* set trace on
|
||||
local nbth:word count `thresholds'
|
||||
forvalues t=1/`nbth' {
|
||||
local th`t':word `t' of `thresholds'
|
||||
}
|
||||
tempname label
|
||||
local recode 0/`th1'=1 `=`th`nbth''+1'/max=`=`nbth'+1'
|
||||
qui label define `label' 1 "0/`th1'",add
|
||||
qui label define `label' `=`nbth'+1' "`=`th`nbth''+1'/max",add
|
||||
forvalues j=2/`nbth' {
|
||||
local recode `recode' `=`th`=`j'-1''+1'/`th`j''=`j'
|
||||
qui label define `label' `j' "`=`th`=`j'-1''+1'/`th`j''",add
|
||||
}
|
||||
|
||||
*di "recode `restscore`i'' `recode'"
|
||||
qui recode `restscore`i'' `recode'
|
||||
qui label values `restscore`i'' `label'
|
||||
local nbgroups=`nbth'+1
|
||||
local minimum=1
|
||||
}
|
||||
else {
|
||||
local nbgroups=`maxscore'
|
||||
local minimum=0
|
||||
}
|
||||
|
||||
forvalues k=1/`modamax`i'' {
|
||||
tempvar rtmp proprestscore`i'`k'
|
||||
if "`cumulative'"!="" {
|
||||
qui gen `rtmp'=``i''>=`k'&``i''!=.
|
||||
bysort `restscore`i'': egen `proprestscore`i'`k''=mean(`rtmp')
|
||||
label variable `proprestscore`i'`k'' "Item ``i''>=`k'"
|
||||
}
|
||||
else {
|
||||
qui gen `rtmp'=``i''==`k'&``i''!=.
|
||||
bysort `restscore`i'': egen `proprestscore`i'`k''=mean(`rtmp')
|
||||
label variable `proprestscore`i'`k'' "Item ``i''=`k'"
|
||||
}
|
||||
local y`i'="`y`i'' `proprestscore`i'`k''"
|
||||
local style="solid"
|
||||
local color="black"
|
||||
local width="medthick"
|
||||
if `modamax`i''==1&"`ci'"!="" {
|
||||
tempvar icrestscoreminus icrestscoreplus
|
||||
qui su `restscore`i''
|
||||
local maxrestscore=r(max)
|
||||
forvalues l=1/`maxrestscore' {
|
||||
qui count if `restscore`i''==`l'
|
||||
local nrestscore`i'=r(N)
|
||||
}
|
||||
qui gen `icrestscoreminus'=`proprestscore`i'1'-1.96*sqrt(`proprestscore`i'1'*(1-`proprestscore`i'1')/`nrestscore`i'')
|
||||
qui gen `icrestscoreplus'=`proprestscore`i'1'+1.96*sqrt(`proprestscore`i'1'*(1-`proprestscore`i'1')/`nrestscore`i'')
|
||||
label variable `icrestscoreminus' "Lower 95% confidence interval"
|
||||
label variable `icrestscoreplus' "Upper 95% confidence interval"
|
||||
local y`i'="`icrestscoreminus' `icrestscoreplus' `proprestscore`i'1'"
|
||||
local style="dash dash solid"
|
||||
local color="red red black"
|
||||
local width="thin thin medthick"
|
||||
}
|
||||
if `modamax`i''==1&"`test'"!="" {
|
||||
qui regress `proprestscore`i'1' `varscore'
|
||||
local p=Fden(e(df_m),e(df_r),e(F))
|
||||
if `p'<0.0001 {
|
||||
local note="Test: slope=0, p<0.0001"
|
||||
}
|
||||
else {
|
||||
local p=substr("`p'",1,6)
|
||||
local note="Test: slope=0, p=`p'"
|
||||
}
|
||||
}
|
||||
}
|
||||
local restscoremax=`scoremax'-`modamax`i''
|
||||
if "``i''"=="`onlyone'"|"`onlyone'"=="" {
|
||||
*tab `proprestscore`i'1' `restscore`i''
|
||||
qui graph twoway (line `y`i'' `restscore`i'', clpattern(`style') clcolor(`color') clwidth(`width')), note("`note'") ylabel(0(0.25)1) xlabel(`minimum'(1)`nbgroups',valuelabel) name(restscore`i',replace) title("Trace of the item ``i'' as a function of the restscore") ytitle("Rate of positive response") `draw'
|
||||
}
|
||||
global restscore "$restscore restscore`i'"
|
||||
if "`restscorefiles'"!="" {
|
||||
graph save restscore`i' `repfiles'\\`restscorefiles'``i'' ,`replace'
|
||||
}
|
||||
}
|
||||
}
|
||||
if "logistic"!="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
qui logistic ``i'' `varscore'
|
||||
tempname coef
|
||||
matrix `coef'=e(b)
|
||||
local pente`i'=`coef'[1,1]
|
||||
local intercept`i'=`coef'[1,2]
|
||||
tempvar logit`i'
|
||||
qui gen `logit`i''=exp(`intercept`i''+`pente`i''*`varscore')/(1+exp(`intercept`i''+`pente`i''*`varscore'))
|
||||
label variable `logit`i'' "Item ``i''"
|
||||
sort `varscore'
|
||||
global logistic "$logistic `logit`i''"
|
||||
}
|
||||
}
|
||||
if "`drawcomb'"!="" {
|
||||
local drawcomb="nodraw"
|
||||
}
|
||||
|
||||
if "`score'"!=""&"`onlyone'"=="" {
|
||||
graph combine $score , title("Trace of the items as a function of the score") name(score,replace) `drawcomb'
|
||||
if "`scorefiles'"!="" {
|
||||
graph save score `repfiles'\\`scorefiles' ,`replace'
|
||||
}
|
||||
}
|
||||
|
||||
if "`restscore'"!=""&"`onlyone'"=="" {
|
||||
graph combine $restscore , title("Trace of the items as a function of the restscores") name(restscore,replace) `drawcomb'
|
||||
if "`restscorefiles'"!="" {
|
||||
graph save restscore `repfiles'\\`restscorefiles' ,`replace'
|
||||
}
|
||||
}
|
||||
if "`logistic'"!="" {
|
||||
graph twoway (line $logistic `varscore'), ylabel(0(0.25)1) xlabel(0(1)`nbitems') title("Logistic traces") ytitle("") name(logistic,replace) `drawcomb'
|
||||
if "`logisticfile'"!="" {
|
||||
graph save logistic `repfiles'\\`logisticfile' ,`replace'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
146
Modules/ado/personal/t/tri.ado
Normal file
146
Modules/ado/personal/t/tri.ado
Normal file
@ -0,0 +1,146 @@
|
||||
program define tri
|
||||
syntax varlist [fweight iweight] [,global test(int 2) all]
|
||||
|
||||
preserve
|
||||
local nbvar:word count `varlist'
|
||||
tokenize `varlist'
|
||||
/*forvalues i=1/`nbvar' {
|
||||
qui su ``i'' [`weight'`exp']
|
||||
qui replace ``i''=(``i''-r(mean))/r(sd)
|
||||
} */
|
||||
|
||||
|
||||
/*METHOD GLOBAL */
|
||||
|
||||
|
||||
/* COVARIANCE OR CORRELATION MATRIX*/
|
||||
|
||||
if "`global'"!="" {
|
||||
tempname Cov W
|
||||
qui matrix accum `Cov'=`varlist' [`weight'`exp'],nocons dev
|
||||
qui matrix `Cov'=`Cov'/(`nbind'-1)
|
||||
matrix `W'=J(2,`nbvar',0)
|
||||
|
||||
local newlist
|
||||
tempvar centroid
|
||||
genscore `varlist',mean score(`centroid')
|
||||
|
||||
forvalues i=1/`nbvar' {
|
||||
qui corr ``i'' `centroid' [`weight'`exp']
|
||||
matrix `W'[1,`i']=`r(rho)'
|
||||
}
|
||||
|
||||
forvalues c=1/`nbvar'{
|
||||
local corrmin=2
|
||||
local var=0
|
||||
forvalues i=1/`nbvar' {
|
||||
if `W'[1,`i']<`corrmin'&`W'[2,`i']==0 {
|
||||
local corrmin=`W'[1,`i']
|
||||
local var=`i'
|
||||
}
|
||||
}
|
||||
matrix `W'[2,`var']=`c'
|
||||
}
|
||||
matrix list `W'
|
||||
forvalues c=1/`nbvar' {
|
||||
forvalues i=1/`nbvar' {
|
||||
if `W'[2,`i']==`c' {
|
||||
local newlist `newlist' ``i''
|
||||
}
|
||||
}
|
||||
}
|
||||
local varlist "`newlist'"
|
||||
tokenize `varlist'
|
||||
}
|
||||
if "`all'"=="" {
|
||||
local time=1
|
||||
}
|
||||
else {
|
||||
local time=`nbvar'
|
||||
}
|
||||
|
||||
local maxc=-99
|
||||
local part
|
||||
forvalues t=1/`time' {
|
||||
tempname W
|
||||
matrix `W'=J(1,`nbvar',0)
|
||||
matrix `W'[1,`t']=1
|
||||
forvalues iter=1/`nbvar' {
|
||||
local dejaselect
|
||||
forvalues i=1/`nbvar' {
|
||||
if `W'[1,`i']!=0 {
|
||||
local dejaselect `dejaselect' ``i''
|
||||
}
|
||||
}
|
||||
tempvar centroid
|
||||
qui genscore `dejaselect',score(`centroid') standardized
|
||||
local maxr=-2
|
||||
local maxi=0
|
||||
forvalues i=1/`nbvar' {
|
||||
if `W'[1,`i']==0 {
|
||||
qui corr `centroid' ``i''
|
||||
local r=r(rho)
|
||||
if `r'>`maxr' {
|
||||
local maxr=`r'
|
||||
local maxi=`i'
|
||||
}
|
||||
}
|
||||
}
|
||||
if `maxi'!=0 {
|
||||
matrix `W'[1,`maxi']=`iter'+1
|
||||
}
|
||||
}
|
||||
local list
|
||||
forvalues class=1/`nbvar' {
|
||||
forvalues i=1/`nbvar' {
|
||||
if `W'[1,`i']==`class' {
|
||||
local list `list' ``i''
|
||||
}
|
||||
}
|
||||
}
|
||||
di "`list'"
|
||||
forvalues i=0/`nbvar' {
|
||||
local j=`nbvar'-`i'
|
||||
if `test'>2 {
|
||||
local jb `j'
|
||||
}
|
||||
else {
|
||||
local jb 0
|
||||
}
|
||||
forvalues k=0/`jb' {
|
||||
local l=`nbvar'-`i'-`k'
|
||||
if `test'>3 {
|
||||
local lb=`l'
|
||||
}
|
||||
else {
|
||||
local lb=0
|
||||
}
|
||||
forvalues m=0/`lb' {
|
||||
local n=`nbvar'-`i'-`k'-`m'
|
||||
qui di "compart `list',part(`i' `k' `m' `n')"
|
||||
di "`i' `k' `m' `n'"
|
||||
if `i'>=0&`k'>=0&`m'>=0&`n'>=0 {
|
||||
di " compart `list',part(`i' `k' `m' `n')"
|
||||
qui compart2 `list',part(`i' `k' `m' `n')
|
||||
local c=r(compart)
|
||||
di "`c'"
|
||||
if `c'>`maxc' {
|
||||
local maxc=`c'
|
||||
local part=r(part)
|
||||
local savlist `list'
|
||||
*di "Best : `c'"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
di "The best partition in two groups is `part'"
|
||||
di "for `savlist'"
|
||||
di "COMPART=`maxc'"
|
||||
|
||||
|
||||
|
||||
|
||||
restore
|
||||
end
|
110
Modules/ado/personal/t/trouve.ado
Normal file
110
Modules/ado/personal/t/trouve.ado
Normal file
@ -0,0 +1,110 @@
|
||||
************************************************************************************************************
|
||||
* Trouve : trouve le nom d'un commune ou d'un canton de la r<>gion centre en indiquant son code
|
||||
*
|
||||
* Version 1.1: 16 aout 2004
|
||||
*
|
||||
* Jean-benoit Hardouin, Observatoire R<>gional de la Sant<6E> du Centre - Orl<72>ans - France
|
||||
* jean-benoit.hardouin@neuf.fr
|
||||
*
|
||||
* Copyright 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 trouve,rclass
|
||||
version 7.0
|
||||
syntax anything
|
||||
local nbarg:word count `anything'
|
||||
capture su *
|
||||
if _rc==0 {
|
||||
tempfile savetrouve
|
||||
qui save `savetrouve',replace
|
||||
}
|
||||
preserve
|
||||
|
||||
numlist "`anything'"
|
||||
local list `r(numlist)'
|
||||
|
||||
foreach i of numlist `list' {
|
||||
if (`i'>1800&`i'<1900)|(`i'>2800&`i'<2900)|(`i'>3600&`i'<3800)|(`i'>4100&`i'<4200)|(`i'>4500&`i'<4600) {
|
||||
qui use "C:\ado\PERSONAL\files\cantons" ,clear
|
||||
qui su id if codepct==`i'
|
||||
local tmp=r(min)
|
||||
local tmp=nompct[`tmp']
|
||||
if "`tmp'"!="" {
|
||||
di in green "`i' (canton):" in yellow " `tmp'"
|
||||
return local trouve`i' "Canton : `tmp'"
|
||||
}
|
||||
else {
|
||||
di in red "Il n'y a pas de canton avec ce numero (`i') dans la region Centre"
|
||||
}
|
||||
}
|
||||
else if `i'>2400&`i'<2500 {
|
||||
local erreur=0
|
||||
if `i'==2411 {local name Bourges}
|
||||
else if `i'==2412 {local name Vierzon}
|
||||
else if `i'==2413 {local name Saint-Amand-Montrond}
|
||||
else if `i'==2414 {local name Aubigny-sur-N<>re}
|
||||
else if `i'==2421 {local name Chartres}
|
||||
else if `i'==2422 {local name Dreux}
|
||||
else if `i'==2423 {local name Chateaudun}
|
||||
else if `i'==2424 {local name Nogent le Rotrou}
|
||||
else if `i'==2431 {local name Chateauroux}
|
||||
else if `i'==2432 {local name Le Blanc}
|
||||
else if `i'==2433 {local name Issoudun}
|
||||
else if `i'==2434 {local name La Chatre}
|
||||
else if `i'==2441 {local name Tours}
|
||||
else if `i'==2442 {local name Amboise}
|
||||
else if `i'==2443 {local name Loches}
|
||||
else if `i'==2444 {local name Chinon}
|
||||
else if `i'==2451 {local name Blois}
|
||||
else if `i'==2452 {local name Vendome}
|
||||
else if `i'==2453 {local name Romoranthin-Lanthenay}
|
||||
else if `i'==2461 {local name Orleans}
|
||||
else if `i'==2462 {local name Montargis}
|
||||
else if `i'==2463 {local name Pithiviers}
|
||||
else if `i'==2464 {local name Gien}
|
||||
else {
|
||||
di in red "Il n'y a pas de zone d'emploi avec ce numero (`i') dans la region Centre"
|
||||
local erreur=1
|
||||
}
|
||||
if `erreur'==0 {
|
||||
di in green "`i' (zone d'emploi):" in yellow " `name'"
|
||||
return local trouve`i' "Zone d'emploi : `name'"
|
||||
}
|
||||
}
|
||||
else if `i'>10000&`i'<100000 {
|
||||
qui use "C:\ado\PERSONAL\files\communes" ,clear
|
||||
qui su id if codecom==`i'
|
||||
local tmp=r(min)
|
||||
local tmp=nomcom[`tmp']
|
||||
if "`tmp'"!="" {
|
||||
di in green "`i' (commune):" in yellow " `tmp'"
|
||||
return local trouve`i' "Commune : `tmp'"
|
||||
}
|
||||
else {
|
||||
di in red "Il n'y a pas de commune avec ce numero (`i') dans la region Centre"
|
||||
}
|
||||
}
|
||||
else {
|
||||
di in red "Ce code n'est pas utilisable"
|
||||
}
|
||||
}
|
||||
restore,not
|
||||
qui drop _all
|
||||
if "`savetrouve'"!="" {
|
||||
qui use `savetrouve'
|
||||
}
|
||||
end
|
Reference in New Issue
Block a user