File restructure #2
This commit is contained in:
61
Modules/ado/plus/t/takelist.ado
Normal file
61
Modules/ado/plus/t/takelist.ado
Normal file
@ -0,0 +1,61 @@
|
||||
program def takelist, rclass
|
||||
*! NJC 1.3.0 14 December 2000
|
||||
* NJC 1.2.0 7 June 2000
|
||||
* NJC 1.1.0 22 Dec 1999
|
||||
* NJC 1.0.0 19 Dec 1999 from a suggestion by Kit Baum
|
||||
version 6.0
|
||||
gettoken list 0 : 0, parse(",")
|
||||
if "`list'" == "" | "`list'" == "," {
|
||||
di in r "nothing in list"
|
||||
exit 198
|
||||
}
|
||||
|
||||
local nlist : word count `list'
|
||||
|
||||
syntax , [ Pos(numlist int >=-`nlist' <=`nlist') Global(str) Noisily ]
|
||||
|
||||
* blanking this out traps a bug if 0 is included in -pos( )-
|
||||
local 0
|
||||
|
||||
if length("`global'") > 8 {
|
||||
di in r "global name must be <=8 characters"
|
||||
exit 198
|
||||
}
|
||||
|
||||
tknz `pos', s(p)
|
||||
local np : word count `pos'
|
||||
|
||||
* negative indexes to positive
|
||||
local i = 1
|
||||
while `i' <= `np' {
|
||||
local p`i' = cond(`p`i'' < 0, `nlist' + 1 + `p`i'', `p`i'')
|
||||
local i = `i' + 1
|
||||
}
|
||||
|
||||
tokenize `list'
|
||||
|
||||
local i = 1
|
||||
while `i' <= `np' {
|
||||
local newlist "`newlist'``p`i''' "
|
||||
local i = `i' + 1
|
||||
}
|
||||
|
||||
if "`noisily'" != "" { di "`newlist'" }
|
||||
if "`global'" != "" { global `global' "`newlist'" }
|
||||
return local list `newlist'
|
||||
end
|
||||
|
||||
program def tknz, rclass
|
||||
* NJC 1.1.0 2 June 2000
|
||||
version 6.0
|
||||
gettoken list 0 : 0, parse(",")
|
||||
syntax , Stub(str) [ * ]
|
||||
tokenize `"`list'"' , `options'
|
||||
|
||||
local i = 1
|
||||
while "``i''" != "" {
|
||||
c_local `stub'`i' `"``i''"'
|
||||
local i = `i' + 1
|
||||
}
|
||||
end
|
||||
|
2
Modules/ado/plus/t/takelist.hlp
Normal file
2
Modules/ado/plus/t/takelist.hlp
Normal file
@ -0,0 +1,2 @@
|
||||
.h listutil
|
||||
|
81
Modules/ado/plus/t/tmpdir.ado
Normal file
81
Modules/ado/plus/t/tmpdir.ado
Normal file
@ -0,0 +1,81 @@
|
||||
*! tmpdir Version 1.1 dan.blanchette@duke.edu 22Jan2009
|
||||
*! Center of Entrepreneurship and Innovation Duke University's Fuqua School of Business
|
||||
* tmpdir Version 1.1 dan_blanchette@unc.edu 16Jan2008
|
||||
* research computing, unc-ch
|
||||
** - minor code updating to improve efficiency of this program
|
||||
** and added check to make sure a Linux/UNIX tmpdir does not
|
||||
** contain spaces.
|
||||
** tmpdir Version 1.0 dan_blanchette@unc.edu 08Oct2003
|
||||
** the carolina population center, unc-ch
|
||||
|
||||
program define tmpdir, rclass
|
||||
args short
|
||||
version 8
|
||||
|
||||
/***************************************************************************************
|
||||
Stata uses the directory that is set by your computer to be the temporary directory
|
||||
by default. The environment variable STATATMP can be set to specific directory that
|
||||
Stata should use for the temporary directory. If you want to have certain programs
|
||||
that call -tmpdir- to use yet another directory for temporary files you can set
|
||||
the location of that temporary directory here with the local macro variable tmpdir.
|
||||
|
||||
If for some reason tmpdir.ado was unable to figure out what the pathname is,
|
||||
enter the name without spaces in the name. For example:
|
||||
local tmpdir=`"c:\Documents and Settings\dan\Local Settings\temp"'
|
||||
should be set using short file names (first 6 characters, plus "~1" or "~2" , etc. :
|
||||
local tmpdir=`"c:\Docume~1\dan\LocalS~1\temp"'
|
||||
****************************************************************************************/
|
||||
|
||||
local tmpdir=`""'
|
||||
|
||||
*****************************************************************
|
||||
******* ! NO MORE EDITS SHOULD BE MADE AFTER THIS POINT ! *******
|
||||
*****************************************************************
|
||||
confirmdir `"`tmpdir'"'
|
||||
if `"`tmpdir'"'=="" | `r(confirmdir)'!=0 { /* tmpdir is not set or not set correctly */
|
||||
tempfile temp
|
||||
_getfilename `"`temp'"'
|
||||
local tfilen `"`r(filename)'"'
|
||||
|
||||
local tmpdir : subinstr local temp `"`tfilen'"' ""
|
||||
|
||||
local subtest : subinstr local tmpdir " " "" , count(local cnt)
|
||||
if `cnt' != 0 {
|
||||
if "`c(os)'"=="Windows" { /* make sure directory structure has no spaces */
|
||||
shortdir using `"`tmpdir'"' , `short'
|
||||
local tmpdir `"`r(shortdir)'\"'
|
||||
} /* end of windows */
|
||||
else {
|
||||
di "{error}Your temporary directory contains spaces."
|
||||
di "{error}You need to set the location of your temporary directory " _n ///
|
||||
"to a directory that does not contain spaces."
|
||||
di "{error}Edit your tmpdir.ado file to set the location of your Stata temporary file: "
|
||||
which tmpdir
|
||||
if "`c(console)'" == "" {
|
||||
di `"It's as easy as: "'
|
||||
di `" {stata adoedit tmpdir: (click here, to edit the tmdpir.ado file}, remember to save when done.)"'
|
||||
}
|
||||
exit 499
|
||||
}
|
||||
} // end of if tmpdir contains spaces
|
||||
capture confirmdir "`macval(tmpdir)'"
|
||||
if `r(confirmdir)'!=0 {
|
||||
di "{error}The setting for your temporary directory: {res}`tmpdir' {error}is not correct."
|
||||
di "{error}You need to set the location of your temporary directory."
|
||||
di "{error}Edit your tmpdir.ado file to set the location of your Stata temporary file: "
|
||||
which tmpdir
|
||||
if "`c(console)'" == "" {
|
||||
di `"It's as easy as: "'
|
||||
di `" {stata adoedit tmpdir: (click here, to edit the tmdpir.ado file}, remember to save when done.)"'
|
||||
}
|
||||
exit 499
|
||||
}
|
||||
} /* end of tmpdir not set or not set correctly */
|
||||
|
||||
return local tmpdir "`tmpdir'"
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
96
Modules/ado/plus/t/tmpdir.hlp
Normal file
96
Modules/ado/plus/t/tmpdir.hlp
Normal file
@ -0,0 +1,96 @@
|
||||
{smcl}
|
||||
{* *! version 1.1 18Jan2008}{...}
|
||||
{* 06Nov2003}{...}
|
||||
{hline}
|
||||
help for {hi:tmpdir} {right:manual: {hi:[R] none}}
|
||||
{right:dialog: {hi: none} }
|
||||
{hline}
|
||||
|
||||
|
||||
{title:Returns the directory Stata is using for a temporary directory `r(tmpdir)'}
|
||||
|
||||
{p 8 17 2}{cmd:tmpdir}
|
||||
[{cmd:short}]{p_end}
|
||||
|
||||
|
||||
{t:itle:Description}
|
||||
|
||||
{p 4 4 2}{cmd:tmpdir} is designed for programmers who want to know what directory Stata
|
||||
writes temp files to. This can be helpful when using the {help file} command
|
||||
to write intermediary files for a program. Since spaces in directory names can
|
||||
cause problems for programs running, {cmd:tmpdir} in the Windows operating system
|
||||
replaces directory / subdirectory names that contain spaces, or optionally any name
|
||||
longer than 8 characters, with the first 6 non-space
|
||||
characters plus "~1" or "~2" (up to "~4"). After that it gets a bit crazy with
|
||||
hexadecimal replacements. {cmd:tmpdir} shells out to DOS and finds the short
|
||||
directory name that DOS has come up with, so there's no attempt to guess the short
|
||||
name. This makes it possible to use this program on many different versions of
|
||||
Windows and always get the short name right. UNIX/Linux systems tend not to have
|
||||
spaces in the directory designated to be the temporary directory, but {cmd:tmpdir}
|
||||
checks for spaces to make sure the temp directory does not have spaces.{p_end}
|
||||
|
||||
{p 4 8 2} Note: {cmd:tmpdir} can be hard coded so that it always chooses a specific directory.
|
||||
This can be helpful if you want to direct large files to your D: drive.{p_end}
|
||||
|
||||
{title:Options}
|
||||
|
||||
{p 4 8 2}{cmd:short} is for Windows only and it specifies that any long directory name
|
||||
should be shortened to 8.3 style names. Not using the {cmd:short} option will allow
|
||||
for long directory names that do not have spaces.{p_end}
|
||||
|
||||
{title:Examples}
|
||||
|
||||
{p 4 8 2}So if your temporary directory is: "C:\Documents and Settings\dan\Local Settings\temp"{p_end}
|
||||
|
||||
{p 4 8 2}{cmd:. tmpdir} returns r(tmpdir):{p_end}
|
||||
|
||||
{p 4 8 2}{cmd:. return list }{p_end}
|
||||
|
||||
{p 4 8 2}{cmd:macros: }{p_end}
|
||||
|
||||
{p 10 10 2}{cmd:r(tmpdir) : "C:\Docume~1\dan\LocalS~1\temp\"}{p_end}
|
||||
|
||||
{p 4 8 2}But if your temp directory is: "C:\Documents and Settings\dan_blanchette\Local Settings\temp"{p_end}
|
||||
|
||||
{p 4 8 2}{cmd:. tmpdir} returns r(tmpdir):{p_end}
|
||||
|
||||
{p 4 8 2}"C:\Docume~1\dan_blanchette\LocalS~1\temp\"{p_end}
|
||||
|
||||
{p 4 8 2}since "dan_blanchette" has no spaces in the name.{p_end}
|
||||
|
||||
{p 4 8 2}{cmd:. tmpdir short} returns r(tmpdir):{p_end}
|
||||
|
||||
{p 4 8 2}"C:\Docume~1\dan_b~1\LocalS~1\temp\"{p_end}
|
||||
|
||||
|
||||
{title:Saved Results}
|
||||
|
||||
{p 4 4 2}The {cmd:tmpdir} command saves in {cmd:r()}:{p_end}
|
||||
|
||||
{p 4 8 2}
|
||||
The {cmd:adoedit} command saves in {cmd:r()}:{p_end}
|
||||
|
||||
{synoptset 20 tabbed}{...}
|
||||
{p2col 5 20 24 2: Macros}{p_end}
|
||||
{synopt:{cmd:r(tmpdir)}}Stata's temporary directory path{p_end}
|
||||
|
||||
|
||||
{title:Author}
|
||||
|
||||
{p 4 4 2}
|
||||
Dan Blanchette {break}
|
||||
Center of Entrepreneurship and Innovation {break}
|
||||
Duke University's Fuqua School of Business {break}
|
||||
Dan.Blanchette@Duke.edu{p_end}
|
||||
|
||||
|
||||
{title:Also see}
|
||||
|
||||
{p 4 13 2}On-line: {help tempfile} {help _getfilename} ,
|
||||
{help confirmdir} (if installed)
|
||||
{help shortdir} (if installed)
|
||||
{help savasas} (if installed)
|
||||
{help usesas} (if installed){p_end}
|
||||
|
||||
|
||||
|
273
Modules/ado/plus/t/torumm.ado
Normal file
273
Modules/ado/plus/t/torumm.ado
Normal file
@ -0,0 +1,273 @@
|
||||
*! torumm.ado version 1.1.2 fw 12/23/00 convert stata files to rumm format
|
||||
*! syntax varlist(numeric) [, FILEname(string) FACTors(varlist numeric max=3) REVerse(varlist) IDvar(varname) ]
|
||||
*! rev 1.1.0 (12/18/01): adds length of label check
|
||||
|
||||
/*
|
||||
itemSeq Sequence of study items
|
||||
testType E = extended/polytomous M = multiple choice
|
||||
itemCode A maximum 5 character code describeing each item
|
||||
itemState A 30 character description (label)
|
||||
respType N = numeric A = alpha
|
||||
respNumb The number of possible responses
|
||||
scKey Scoring key: blank or R for reversed
|
||||
respSeq 0 to 5 for numeric, A to E for alpha (the lowest level of response)
|
||||
|
||||
itemSeq testType itemCode itemState respType respNumb scKey respSeq
|
||||
1 E I0001 Descriptor for Item 1 N 4 1
|
||||
2 E I0002 Descriptor for Item 2 N 4 R 1
|
||||
3 E I0003 Descriptor for Item 3 N 4 1
|
||||
4 E I0004 Descriptor for Item 4 N 4 R 1
|
||||
5 E I0005 Descriptor for Item 5 N 4 R 1
|
||||
6 E I0006 Descriptor for Item 6 N 4 R 1
|
||||
7 E I0007 Descriptor for Item 7 N 4 1
|
||||
8 E I0008 Descriptor for Item 8 N 4 R 1
|
||||
9 E I0009 Descriptor for Item 9 N 4 R 1
|
||||
10 E I0010 Descriptor for Item 10 N 4 1
|
||||
11 E I0011 Descriptor for Item 11 N 4 R 1
|
||||
12 E I0012 Descriptor for Item 12 N 4 1
|
||||
13 E I0013 Descriptor for Item 13 N 4 R 1
|
||||
14 E I0014 Descriptor for Item 14 N 4 1
|
||||
15 E I0015 Descriptor for Item 15 N 4 1
|
||||
16 E I0016 Descriptor for Item 16 N 4 R 1
|
||||
|
||||
*/
|
||||
|
||||
program define torumm
|
||||
version 6.0
|
||||
syntax varlist(numeric) [, FILEname(string) FACTors(varlist numeric max=3) REVerse(varlist) IDvar(varname) ]
|
||||
tokenize `varlist'
|
||||
|
||||
set more off
|
||||
|
||||
preserve
|
||||
|
||||
/* Process spc file items */
|
||||
|
||||
qui dropvars itemSeq testType itemCode itemStat respType respNumb scKey respSeq
|
||||
|
||||
di "Building SPC file ..."
|
||||
qui gen byte itemSeq = .
|
||||
qui gen str1 testType = "E"
|
||||
qui gen str5 itemCode = ""
|
||||
qui gen str30 itemStat = ""
|
||||
qui gen str1 respType = "N"
|
||||
qui gen byte respNumb = .
|
||||
qui gen str1 scKey = ""
|
||||
qui gen byte respSeq = .
|
||||
|
||||
|
||||
if "`ttype'" == ""{
|
||||
local ttype E
|
||||
}
|
||||
if "`rtype'" == ""{
|
||||
local rtype N
|
||||
}
|
||||
|
||||
local wcount: word count `varlist'
|
||||
local varnum 0
|
||||
while `"`1'"' != ""{
|
||||
local varnum `varnum' + 1
|
||||
local label : variable label `1'
|
||||
local vword "`1'"
|
||||
* di "`1'" " " "`label'"
|
||||
* di `vanum'
|
||||
qui replace itemStat = "`label'" if _n == `varnum'
|
||||
qui replace itemStat = "`vword'" if itemStat == "" & _n == `varnum'
|
||||
qui replace itemSeq = _n if _n == `varnum'
|
||||
qui replace itemCode = "I" + string(_n) if _n == `varnum'
|
||||
qui su `1'
|
||||
qui replace respNumb = (r(max) - r(min)) + 1 if _n == `varnum'
|
||||
qui replace respSeq = r(min) if _n == `varnum'
|
||||
qui bothlist `1' \ `reverse'
|
||||
if "`r(list)'" == "`1'" {
|
||||
qui replace scKey = "R" if _n == `varnum'
|
||||
}
|
||||
|
||||
mac shift
|
||||
}
|
||||
qui compress
|
||||
listblck itemSeq - respSeq in 1 / `wcount'
|
||||
qui outsheet itemSeq-respSeq using "`filename'.spc" in 1 / `wcount',noquote replace
|
||||
|
||||
|
||||
|
||||
|
||||
/* Process itm file items */
|
||||
|
||||
qui tostring `varlist', nodecode /* convert study variables to strings */
|
||||
qui dropvars blockID segID comments blockS blockW TestType RespType itemLen itemSubN missSymb
|
||||
|
||||
|
||||
/* We convert the ID variable to a string format */
|
||||
local type : type `idvar'
|
||||
if substr("`type'",1,3) != "str" {qui tostring `idvar', f(%5.0f)}
|
||||
recast str5 `idvar'
|
||||
qui replace `idvar' = ltrim(`idvar')
|
||||
qui moreobs
|
||||
qui gen order = _n
|
||||
qui replace `idvar' ="aaaaa" in l
|
||||
|
||||
qui gen blockID = _n /* Data should be in order required before running this program */
|
||||
qui gen str2 segID = ""
|
||||
qui gen str30 comments = ""
|
||||
qui gen byte blockS = .
|
||||
qui gen blockW = .
|
||||
qui gen byte TestType = 0
|
||||
qui gen byte RespType = 0
|
||||
qui gen byte itemLen = 0
|
||||
qui gen itemSubN = 0
|
||||
qui gen str3 missSymb = "bsp"
|
||||
|
||||
/* enter blockID data *** This is for line 1*/
|
||||
qui replace blockID = 1 in 1
|
||||
qui replace segID = "1" in 1
|
||||
qui replace comments = "ID" in 1
|
||||
qui replace blockS = 1 in 1
|
||||
qui replace blockW = 5 in 1
|
||||
local block = 1
|
||||
|
||||
if "`factors'" != ""{
|
||||
unab cats : `factors'
|
||||
tokenize "`cats'"
|
||||
local facount : word count `cats'
|
||||
*di "Number of factor variables = " "`facount'"
|
||||
local counter = 0
|
||||
local starter = 7 /* we begin variable placement counting at 30 */
|
||||
/* we have skipped a space so lets add the spacer to the output template */
|
||||
sort order
|
||||
qui gen str1 space1 = ""
|
||||
qui replace space1 = "s" in l
|
||||
|
||||
/* we have to do the same for the factors - we will do do below */
|
||||
while `"`1'"' != ""{
|
||||
local counter = `counter' + 1
|
||||
local facword : word `counter' of `cats'
|
||||
qui tab `1'
|
||||
*di "Variable (" `counter' ") " "`1'" " has " `r(r)' " levels"
|
||||
local block = `block' + 1
|
||||
qui replace blockID in `block' = `block'
|
||||
|
||||
/* Now we enter the factor data - the variable name goes first*/
|
||||
qui replace segID = "2" in `block'
|
||||
local label : variable label `1'
|
||||
if length("`label'") >5 {
|
||||
di
|
||||
di in red "label for `1' (`label') is more than 5 characters in length"
|
||||
exit 198
|
||||
}
|
||||
if "`label'" != "" {
|
||||
qui replace comments = "`label'" in `block'
|
||||
}
|
||||
else {qui replace comments = "`1'" in `block'}
|
||||
|
||||
qui replace blockS = `starter' in `block'
|
||||
qui replace blockW = 1 in `block'
|
||||
local starter = `starter' + 1
|
||||
|
||||
/* Now we move to the labelled categories & move down a row */
|
||||
local block = `block' + 1
|
||||
qui replace blockID in `block' = `block'
|
||||
qui tab `1' /* The number of levels is r(r) then `catlev'*/
|
||||
local catlev = `r(r)'
|
||||
qui vallist `1',label s(^)
|
||||
local avals `r(list)'
|
||||
local avals : subinstr local avals " " "_", all
|
||||
local avals : subinstr local avals "^" " ", all
|
||||
qui vallist `1'
|
||||
local nvals `r(list)'
|
||||
local vcount = 1
|
||||
*di "Alpha list = " "`avals'"
|
||||
*di "Numerical list = " "`nvals'"
|
||||
*di
|
||||
|
||||
while `vcount' <= `catlev' {
|
||||
|
||||
local aword : word `vcount' of `avals'
|
||||
local nword : word `vcount' of `nvals'
|
||||
qui replace comments = "`aword'" in `block'
|
||||
qui replace segID = "2`counter'" in `block'
|
||||
qui replace blockS = `counter' in `block'
|
||||
qui replace blockW = `nword' in `block'
|
||||
qui replace missSymb = "0" in `block'
|
||||
*di "`aword'" " " "`nword'"
|
||||
if `vcount' != `catlev' {local block = `block' + 1 }
|
||||
local vcount = `vcount' + 1
|
||||
}
|
||||
qui tostring `1', nod
|
||||
sort order
|
||||
qui replace `1' = "f" in l
|
||||
mac shift
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
di "No factor model"
|
||||
qui gen str1 space1 = ""
|
||||
qui replace space1 = "s" in l
|
||||
local starter = 7
|
||||
}
|
||||
|
||||
/* Now begin the placement of variables */
|
||||
local block = `block' + 1
|
||||
local starter = `starter' + 2
|
||||
sort order
|
||||
qui gen str2 space2 = ""
|
||||
qui replace space2 = "ss" in l
|
||||
qui replace segID = "3" in `block'
|
||||
qui replace comments = "Items" in `block'
|
||||
qui replace blockS = `starter' in `block'
|
||||
qui replace blockW =`varnum' in `block'
|
||||
qui compress comments
|
||||
qui replace TestType = 1 in `block'
|
||||
qui replace RespType = 1 in `block'
|
||||
qui replace itemLen = 1 in `block'
|
||||
qui replace itemSubN = `varnum' in `block'
|
||||
|
||||
/* replace varlist here with v */
|
||||
tokenize `varlist'
|
||||
while `"`1'"' != ""{
|
||||
qui replace `1' = "v" in l
|
||||
mac shift
|
||||
}
|
||||
listblck blockID segID comments blockS blockW TestType RespType itemLen itemSubN missSymb in 1 / `block'
|
||||
qui outsheet blockID segID comments blockS blockW TestType RespType itemLen itemSubN missSymb using "`filename'.itm" in 1 / `block',noquote replace
|
||||
|
||||
/* We can now concatenate into a long string */
|
||||
|
||||
*format `idvar' %030s
|
||||
|
||||
if "`factors'" != ""{
|
||||
local outvar "`idvar' space1 `cats' space2 `varlist'"
|
||||
}
|
||||
else {local outvar "`idvar' space1 space2 `varlist'"}
|
||||
tokenize `outvar'
|
||||
while `"`1'"' != ""{
|
||||
qui replace `1' = "^^^^^^^^^^^^^^^^^^^^" if `1' == "",nop
|
||||
mac shift
|
||||
}
|
||||
local outvar : subinstr local outvar " " "+" , all
|
||||
*di "`outvar'"
|
||||
gen str80 outvar = `outvar'
|
||||
sort order
|
||||
local lcount = 0
|
||||
while `lcount' < _N {
|
||||
local lcount = `lcount' + 1
|
||||
local tempout = outvar in `lcount'
|
||||
local sub : subinstr local tempout "^" " " , all
|
||||
qui replace outvar = "`sub'" in `lcount'
|
||||
}
|
||||
qui compress outvar
|
||||
qui drop in l
|
||||
di "`file'"
|
||||
*format outvar %-080s
|
||||
outfile outvar using `filename'.dat, wide replace noq
|
||||
l outvar
|
||||
restore
|
||||
di
|
||||
su `varlist'
|
||||
|
||||
di
|
||||
di "Files Created: (1) `filename'.scr (2) `filename'.itm (3) `filename'.dat"
|
||||
|
||||
end
|
||||
|
89
Modules/ado/plus/t/torumm.hlp
Normal file
89
Modules/ado/plus/t/torumm.hlp
Normal file
@ -0,0 +1,89 @@
|
||||
.-
|
||||
help for ^torumm^
|
||||
.-
|
||||
|
||||
^Format and transfer data to RUMM^
|
||||
-------------------------------
|
||||
|
||||
syntax varlist [, FILEname(string) FACTors(string) IDvar(varname) REVerse ]
|
||||
|
||||
|
||||
^Description^
|
||||
-----------
|
||||
|
||||
^torumm^ prepares a Stata dataset for analysis in ^RUMM^), a Rasch analysis
|
||||
package. Two control files (.spc .itm) and a data file (.dat) are created
|
||||
using using the Stata ^outsheet^ and outfile commands. ^torumm^ is
|
||||
non-destructive in that does not alter the Stata data. ^varlist^
|
||||
refers to the variables that will be studied in the Rasch analysis. The
|
||||
"factor" variables are categorical variables that subset the analyses.
|
||||
|
||||
|
||||
^Options^
|
||||
-------
|
||||
|
||||
^FILEname(string)^: the name of the files to be saved as -spc-, itm- and
|
||||
-dat- files in Rumm.
|
||||
|
||||
^FACTors(varlist)^: the factorial or categorical variables (subsetting).
|
||||
Rumm only allows 3 factors. Factor label cannot be longer than 5 characters.
|
||||
|
||||
^IDvar^: the name of the ID variable. This can be up to 5 charters in length
|
||||
or between 0 and 99,999, if numeric.
|
||||
|
||||
^REVerse^: varlist of variables that are reversed scored.
|
||||
|
||||
|
||||
^Comments^
|
||||
--------
|
||||
|
||||
The current version of ^torumm^ has a number of restrictions: (1) only
|
||||
numeric variables are allowed in the varlist and list of factor variables.
|
||||
(2) only integers between 0-9 are to be used for the varlist and factor
|
||||
variable values. (3) This version of ^torumm^ suuports rating scale
|
||||
but not multiple choice variables. By default the RUMM variable ^testType^
|
||||
has been set to E for extended or polytomous (rating scale). In addition,
|
||||
^respType^ has been set to the default of N (numeric). (4) Because of
|
||||
the 80 character string limitation on Stata,a maximum of 69 variables
|
||||
should be entered as the varlist in order to stay within the 80 character
|
||||
limitation.
|
||||
|
||||
^Sort order of the variables^ If you want a special order to the variables
|
||||
be sure to order the variables in the desired order with ^order^.
|
||||
|
||||
The number of responses or ^respNum^ is calculated from min and max values.
|
||||
If the item does not have a score at the minumum or maximum value then
|
||||
the ^respNum^ will be incorrect (in one sense). ^respNum^ should be checked
|
||||
by viewing the program output or by hand in the RUMM editor or a spread sheet
|
||||
to be sure the calculated values are correct.
|
||||
|
||||
The lowest code number for the responses or ^respSeq^ is calculated
|
||||
from the minimum value. If the item does not have a score at the minumum
|
||||
value then the ^respSeq^ will be incorrect (in one sense). ^respSeq^ should
|
||||
be checked in the program output or by hand in the RUMM editor or a spread
|
||||
sheet to be sure the calculated values are correct.
|
||||
|
||||
^torumm^ makes use of value labels, if present, otherwise it uses numeric
|
||||
codes. Similarly, variables labels are used when present; if not present,
|
||||
variable name is substituted for the variable label.
|
||||
|
||||
|
||||
If Stata 6.0 is being used, ^torumm^ requires the presence of -vallist-,
|
||||
-tostring- and -bothlist-, programs of Nick Cox that are available on the BC
|
||||
Archives. ^torumm^ also works with Stata 7.0.
|
||||
|
||||
|
||||
^Examples^
|
||||
--------
|
||||
|
||||
. torumm mcp_eros - m_nav_n1, file(shrumm) id(newpat) rev(mcp_nar1 mcp_nar2)
|
||||
. torumm mcp_eros - m_nav_n1, file(shrumm) id(patkey) factors(durgroup)
|
||||
|
||||
^Author^
|
||||
------
|
||||
|
||||
Fred Wolfe
|
||||
National Data Bank for Rheumatic Diseases
|
||||
fwolfe@@arthritis-research.org
|
||||
|
||||
|
309
Modules/ado/plus/t/traces.ado
Normal file
309
Modules/ado/plus/t/traces.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
|
||||
|
||||
|
100
Modules/ado/plus/t/traces.hlp
Normal file
100
Modules/ado/plus/t/traces.hlp
Normal file
@ -0,0 +1,100 @@
|
||||
{smcl}
|
||||
{* 14june2007}{...}
|
||||
{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}Websites {browse "http://www.anaqol.org":AnaQol}
|
||||
and {browse "http://www.freeirt.org":FreeIRT}
|
||||
|
||||
{title:Also see}
|
||||
|
||||
{p 4 13 2}Online: help for {help graph}, {help loevH} and {help gengroup} if installed.{p_end}
|
542
Modules/ado/plus/t/traj.ado
Normal file
542
Modules/ado/plus/t/traj.ado
Normal file
@ -0,0 +1,542 @@
|
||||
*! traj - May 17, 2013 Bobby L Jones
|
||||
**********************************************************************************
|
||||
program traj, eclass
|
||||
|
||||
version 9
|
||||
|
||||
syntax [if] [in], Model1(str) Var1(varlist numeric) Indep1(varlist numeric) ///
|
||||
Order1(numlist int >=-1 <=5) ///
|
||||
[ Min1(real 0.0) Max1(real 1e-38) Iorder1(numlist int >=-1 <=5) ///
|
||||
Risk1(varlist numeric) Weight1(varlist numeric) Expos1(varlist numeric) ///
|
||||
Tcov1(varlist numeric) Plottcov1(string) Refgroup1(int 1) ///
|
||||
Dropout1(numlist int >=-1 <=2) Dcov1(varlist numeric) Obsmar1(varlist numeric) ///
|
||||
Outcome1(varlist numeric) Omodel1(str) Rorder1(numlist int >=-1 <=3) ///
|
||||
Model2(str) Var2(varlist numeric) Indep2(varlist numeric) ///
|
||||
Order2(numlist int >=-1 <=5) Min2(real 0.0) Max2(real 1e-38) ///
|
||||
Iorder2(numlist int >=-1 <=5) Risk2(varlist numeric) Expos2(varlist numeric) ///
|
||||
Tcov2(varlist numeric) Refgroup2(int 1) Dropout2(numlist int >=-1 <=2) ///
|
||||
Model3(str) Var3(varlist numeric) Indep3(varlist numeric) ///
|
||||
Order3(numlist int >=-1 <=5) Min3(real 0.0) Max3(real 1e-38) ///
|
||||
Iorder3(numlist int >=-1 <=5) Risk3(varlist numeric) Expos3(varlist numeric) ///
|
||||
Tcov3(varlist numeric) Dropout3(numlist int >=-1 <=2) ///
|
||||
Multgroups(integer 0) Start(string) DETAIL TRACE NOVAR OUTOFSAMPLEPROBS]
|
||||
|
||||
marksample touse
|
||||
quietly count if `touse'
|
||||
|
||||
local maxmodels = 3
|
||||
|
||||
if `r(N)' == 0 {
|
||||
error 2000
|
||||
}
|
||||
|
||||
local rN = `r(N)'
|
||||
|
||||
forval i = 2/`maxmodels' {
|
||||
if ( length( "`model`i''" ) == 0 ) {
|
||||
local model`i' = "none"
|
||||
}
|
||||
}
|
||||
|
||||
local itdetail = 0
|
||||
if "`detail'" == "detail" {
|
||||
local itdetail = 1
|
||||
}
|
||||
|
||||
local ittrace = 0
|
||||
if "`trace'" == "trace" {
|
||||
local ittrace = 1
|
||||
}
|
||||
|
||||
local itnovar = 0
|
||||
if "`novar'" == "novar" {
|
||||
local itnovar = 1
|
||||
}
|
||||
|
||||
local oosprobs = 0
|
||||
if "`outofsampleprobs'" == "outofsampleprobs" {
|
||||
local oosprobs = 1
|
||||
}
|
||||
|
||||
local traj_start_len = 0
|
||||
|
||||
if "`start'" != "" {
|
||||
cap confirm matrix `start'
|
||||
if _rc {
|
||||
di as err "Error: start must specify a matrix"
|
||||
exit 198
|
||||
}
|
||||
tempname traj_start
|
||||
local traj_start_len = colsof(`start')
|
||||
matrix traj_start = `start'
|
||||
}
|
||||
|
||||
local plottcov1_len = 0
|
||||
|
||||
if "`plottcov1'"!="" {
|
||||
cap confirm matrix `plottcov1'
|
||||
if _rc {
|
||||
di as err "Error: plottcov1 must specify a matrix"
|
||||
exit 198
|
||||
}
|
||||
tempname traj_plottcov1
|
||||
local plottcov1_len = colsof(`plottcov1')
|
||||
matrix traj_plottcov1 = `plottcov1'
|
||||
}
|
||||
|
||||
forval i = 1/`maxmodels' {
|
||||
|
||||
if !("`model`i''" == "none") {
|
||||
|
||||
if ( "`model`i''" != "cnorm" & "`model`i''" != "zip" &"`model`i''" != "logit" ) {
|
||||
di as err "Error: model`i' is not cnorm, zip, or logit."
|
||||
exit 198
|
||||
}
|
||||
|
||||
if "`model`i''"=="cnorm" {
|
||||
if `max`i'' == 1e-38 {
|
||||
di as err "Error: max`i' required for model`i' cnorm."
|
||||
exit 198
|
||||
}
|
||||
|
||||
tokenize "`var`i''"
|
||||
while "`1'" != "" {
|
||||
local vr `1'
|
||||
cap sum `vr'
|
||||
cap assert r(min) >= `min`i'' & r(max) <= `max`i''
|
||||
if _rc {
|
||||
di as err "`vr' is not within min`i' = `min`i'' and max`i' = `max`i''."
|
||||
exit 198
|
||||
}
|
||||
mac shift
|
||||
}
|
||||
}
|
||||
|
||||
if "`model`i''"=="logit" {
|
||||
tokenize "`var`i''"
|
||||
while "`1'" != "" {
|
||||
local vr `1'
|
||||
cap assert `vr' == 0 | `vr' == 1 | `vr' >= .
|
||||
if _rc {
|
||||
di as err "Error: `vr' is not 0/1 (logit model)."
|
||||
exit 198
|
||||
}
|
||||
mac shift
|
||||
}
|
||||
}
|
||||
|
||||
if "`model`i''"=="zip" {
|
||||
tokenize "`var`i''"
|
||||
while "`1'" != "" {
|
||||
local vr `1'
|
||||
cap assert `vr' >= 0
|
||||
if _rc {
|
||||
di as err "Error: `vr' has negative values (zip model)."
|
||||
exit 198
|
||||
}
|
||||
mac shift
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
local numindep`i' : word count `indep`i''
|
||||
local numvar`i' : word count `var`i''
|
||||
if ( `numindep`i'' != `numvar`i'' ) {
|
||||
di as err "Error: number of variables in var`i' and indep`i' must match."
|
||||
exit 198
|
||||
}
|
||||
|
||||
local numrisk`i' : word count `risk`i''
|
||||
local numexpos`i' : word count `expos`i''
|
||||
local numtcov`i' : word count `tcov`i''
|
||||
local numdcov`i' : word count `dcov`i''
|
||||
local numoutcome`i' : word count `outcome`i''
|
||||
local numweight`i' : word count `weight`i''
|
||||
local numobsmar`i' : word count `obsmar`i''
|
||||
|
||||
|
||||
if ( `numoutcome`i'' > 0 ) {
|
||||
|
||||
if ( "`omodel`i''" != "normal" & "`omodel`i''" != "cnorm" & ///
|
||||
"`omodel`i''" != "poisson" & ///
|
||||
"`omodel`i''" != "logit" & "`omodel`i''" != "none" ) {
|
||||
di as err "Error: omodel`i' is not normal, cnorm, poisson, or logit."
|
||||
exit 198
|
||||
}
|
||||
|
||||
/*
|
||||
if "`omodel`i''"=="cnorm" {
|
||||
if `max`i'' == 1e-38 {
|
||||
di as err "Error: max`i' required for model`i' cnorm."
|
||||
exit 198
|
||||
}
|
||||
cap sum `outcome`i''
|
||||
cap assert r(min) >= `omin`i'' & r(max) <= `omax`i''
|
||||
if _rc {
|
||||
di as err "`outcome`i'' is not within omin`i' = `omin`i'' and omax`i' = `omax`i''."
|
||||
exit 198
|
||||
}
|
||||
}
|
||||
*/
|
||||
if "`omodel`i''"=="logit" {
|
||||
cap assert `outcome`i'' == 0 | `outcome`i'' == 1 | `outcome`i'' >= .
|
||||
if _rc {
|
||||
di as err "Error: `outcome`i'' is not 0/1 (logit model)."
|
||||
exit 198
|
||||
}
|
||||
}
|
||||
|
||||
if "`omodel`i''"=="poisson" {
|
||||
cap assert `outcome`i'' >= 0
|
||||
if _rc {
|
||||
di as err "Error: `outcome`i'' has negative values (poisson model)."
|
||||
exit 198
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( `numexpos`i'' > 1 ) {
|
||||
tokenize "`expos`i''"
|
||||
while "`1'" != "" {
|
||||
local vr `1'
|
||||
cap assert `vr' > 0
|
||||
if _rc {
|
||||
di as err "Error: exposure variable `vr' is not > 0."
|
||||
exit 198
|
||||
}
|
||||
mac shift
|
||||
}
|
||||
if ( `numexpos`i'' != `numvar`i'' ) {
|
||||
di as err "Error: number of variables in var`i' and expos`i' must match."
|
||||
exit 198
|
||||
}
|
||||
if ( "`model`i''" != "zip" ) {
|
||||
di as err "Error: exposure is only allowed with the zip model."
|
||||
exit 198
|
||||
}
|
||||
}
|
||||
|
||||
if ( `numoutcome`i'' > 1 ) {
|
||||
di as err "Error: only one variable is allowed for outcome`i'."
|
||||
exit 198
|
||||
}
|
||||
|
||||
if ( `numobsmar`i'' > 1 ) {
|
||||
di as err "Error: only one variable is allowed for obsmar`i'."
|
||||
exit 198
|
||||
}
|
||||
|
||||
if ( `numtcov`i'' != 0 & `numtcov`i'' / `numindep`i'' != int( `numtcov`i'' / `numindep`i'' ) ) {
|
||||
di as err "Error: number of variables in tcov`i' and var`i' must match or be a multiple."
|
||||
exit 198
|
||||
}
|
||||
|
||||
if ( `numdcov`i'' != 0 & `numdcov`i'' / `numindep`i'' != int( `numdcov`i'' / `numindep`i'' ) ) {
|
||||
di as err "Error: number of variables in dcov`i' and var`i' must match or be a multiple."
|
||||
exit 198
|
||||
}
|
||||
|
||||
if (length("`omodel`i''")==0) {
|
||||
local omodel`i'="none"
|
||||
}
|
||||
}
|
||||
|
||||
if ( `plottcov1_len' != 0 & `plottcov1_len' / `numindep1' != int( `plottcov1_len' / `numindep1' ) ) {
|
||||
di as err "Error: there should be `numtcov1' values for plottcov1."
|
||||
exit 198
|
||||
}
|
||||
|
||||
if ( `numweight1' > 1 ) {
|
||||
di as err "Error: only one variable is allowed for weight."
|
||||
exit 198
|
||||
}
|
||||
|
||||
forval i = 1/`maxmodels' {
|
||||
local numorder`i' 0
|
||||
tokenize "`order`i''"
|
||||
while "`1'" != "" {
|
||||
local numorder`i' = `numorder`i'' + 1
|
||||
local c`numorder`i'' `1'
|
||||
local ordr`i' "`ordr`i'' "`1'""
|
||||
mac shift
|
||||
}
|
||||
|
||||
if ( `numorder`i'' != 0 ) {
|
||||
matrix traj_mat_order`i' = J( 1, `numorder`i'', 0 )
|
||||
tokenize "`order`i''"
|
||||
forval j = 1/`numorder`i'' {
|
||||
matrix traj_mat_order`i'[1,`j'] = real("`1'")
|
||||
mac shift
|
||||
}
|
||||
}
|
||||
|
||||
local numiorder`i' 0
|
||||
tokenize "`iorder`i''"
|
||||
while "`1'" != "" {
|
||||
local numiorder`i' = `numiorder`i'' + 1
|
||||
local c`numiorder`i'' `1'
|
||||
local iordr`i' "`iordr`i'' "`1'""
|
||||
mac shift
|
||||
}
|
||||
|
||||
if ( `numiorder`i'' != 0 ) {
|
||||
matrix traj_mat_iorder`i' = J( 1, `numiorder`i'', 0 )
|
||||
tokenize "`iorder`i''"
|
||||
forval j = 1/`numiorder`i'' {
|
||||
matrix traj_mat_iorder`i'[1,`j'] = real("`1'")
|
||||
mac shift
|
||||
}
|
||||
}
|
||||
|
||||
if ( "`model`i''" != "zip" & `numiorder`i'' != 0 ) {
|
||||
di as err "Error: iorder is only allowed with the zip model."
|
||||
exit 198
|
||||
}
|
||||
|
||||
if ( `numiorder`i'' != `numorder`i'' & `numiorder`i'' != 1 & `numiorder`i'' != 0 ) {
|
||||
di as err "Error: there should be 1 or `numorder`i'' iorders for iorder`i'."
|
||||
exit 198
|
||||
}
|
||||
}
|
||||
|
||||
if ( `numrisk1' > 0 ) {
|
||||
if ( `numorder1' < 2 ) {
|
||||
di as err "Error: risk is only valid when the number of groups is > 1."
|
||||
exit 198
|
||||
}
|
||||
}
|
||||
|
||||
if ( `refgroup1' > 1 ) {
|
||||
if ( `numrisk1' == 0 ) {
|
||||
di as err "Error: refgroup is only valid when the risk is specified."
|
||||
exit 198
|
||||
}
|
||||
if ( `refgroup1' > `numorder1' ) {
|
||||
di as err "Error: refgroup exceeds the number of groups."
|
||||
exit 198
|
||||
}
|
||||
}
|
||||
|
||||
if ( `refgroup2' > 1 ) {
|
||||
if ( `numrisk2' == 0 ) {
|
||||
di as err "Error: refgroup2 is only valid when the risk2 is specified."
|
||||
exit 198
|
||||
}
|
||||
if ( `refgroup2' > `numorder2' ) {
|
||||
di as err "Error: refgroup2 exceeds the number of groups."
|
||||
exit 198
|
||||
}
|
||||
}
|
||||
|
||||
local numrorder1 0
|
||||
tokenize "`rorder1'"
|
||||
while "`1'" != "" {
|
||||
local numrorder1 = `numrorder1' + 1
|
||||
local c`numrorder1' `1'
|
||||
local rordr1 "`rordr1' "`1'""
|
||||
mac shift
|
||||
}
|
||||
|
||||
if ( `numrorder1' != 0 ) {
|
||||
matrix traj_mat_rorder1 = J( 1, `numrorder1', 0 )
|
||||
tokenize "`rorder1'"
|
||||
forval i = 1/`numrorder1' {
|
||||
matrix traj_mat_rorder1[1,`i'] = real("`1'")
|
||||
mac shift
|
||||
}
|
||||
}
|
||||
/*
|
||||
if ( `numrorder1' > 0 ) {
|
||||
di as err "rorder is experimental and may be available. Contact bjones@andrew.cmu.edu"
|
||||
exit 198
|
||||
}
|
||||
*/
|
||||
if ( "`model1'" != "cnorm" & `numrorder1' != 0 ) {
|
||||
di as err "Error: rorder is only supported for the cnorm model."
|
||||
exit 198
|
||||
}
|
||||
|
||||
local numdropout1 0
|
||||
tokenize "`dropout1'"
|
||||
while "`1'" != "" {
|
||||
local numdropout1 = `numdropout1' + 1
|
||||
local c`numdropout1' `1'
|
||||
local drpout1 "`drpout1' "`1'""
|
||||
mac shift
|
||||
}
|
||||
|
||||
if ( `numdropout1' != 0 ) {
|
||||
matrix traj_mat_dropoutorder1 = J( 1, `numdropout1', 0 )
|
||||
tokenize "`dropout1'"
|
||||
forval i = 1/`numdropout1' {
|
||||
matrix traj_mat_dropoutorder1[1,`i'] = real("`1'")
|
||||
mac shift
|
||||
}
|
||||
}
|
||||
|
||||
local numdropout2 0
|
||||
local numdropout3 0
|
||||
|
||||
cap qui drop _traj_Group
|
||||
qui gen _traj_Group = .
|
||||
cap qui drop _traj_Prob*
|
||||
local out1 "_traj_Group"
|
||||
forvalues j = 1/`numorder1' {
|
||||
qui gen _traj_ProbG`j' = .
|
||||
local out1 "`out1' _traj_ProbG`j'"
|
||||
}
|
||||
|
||||
local outMat `out1'
|
||||
|
||||
if ( `numorder2' != 0 & `multgroups' == 0 ) {
|
||||
cap qui drop _traj_Model2_Group
|
||||
qui gen _traj_Model2_Group = .
|
||||
local out2 "_traj_Model2_Group"
|
||||
forvalues j = 1/`numorder2' {
|
||||
cap qui drop _traj_Model2_ProbG`j'
|
||||
qui gen _traj_Model2_ProbG`j' = .
|
||||
local out2 "`out2' _traj_Model2_ProbG`j'"
|
||||
}
|
||||
local outMat "`outMat' `out2'"
|
||||
}
|
||||
/*
|
||||
if ( `multgroups' == 0 ) {
|
||||
forval i = 2/`maxmodels' {
|
||||
if `numorder`i'' != 0 {
|
||||
cap qui drop _traj_Model`i'_Group
|
||||
qui gen _traj_Model`i'_Group = .
|
||||
local out`i' "_traj_Model`i'_Group"
|
||||
forvalues j = 1/`numorder`i'' {
|
||||
cap qui drop _traj_Model`i'_ProbG`j'
|
||||
qui gen _traj_Model`i'_ProbG`j' = .
|
||||
local out`i' "`out`i'' _traj_Model`i'_ProbG`j'"
|
||||
}
|
||||
local outMat "`outMat' `out`i''"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
forval i = 1/`maxmodels' {
|
||||
if `numorder`i'' != 0 {
|
||||
local plotVarLabels`i' "trajT"
|
||||
|
||||
forvalues j = 1/`numorder`i'' {
|
||||
local plotVarLabels`i' "`plotVarLabels`i'' Avg`j'"
|
||||
}
|
||||
forvalues j = 1/`numorder`i'' {
|
||||
local plotVarLabels`i' "`plotVarLabels`i'' Est`j'"
|
||||
}
|
||||
forvalues j = 1/`numorder`i'' {
|
||||
local plotVarLabels`i' "`plotVarLabels`i'' L95`j'"
|
||||
local plotVarLabels`i' "`plotVarLabels`i'' U95`j'"
|
||||
}
|
||||
}
|
||||
tokenize "`plotVarLabels`i''"
|
||||
}
|
||||
|
||||
if `numdropout1' != 0 {
|
||||
if ( `numdropout1' != 1 & `numdropout1' != `numorder1' ) {
|
||||
di as err "Error: there should be 1 or `numorder`i'' values for dropout."
|
||||
exit 198
|
||||
}
|
||||
forvalues j = 1/`numdropout1' {
|
||||
local plotVarLabels1 "`plotVarLabels1' Dropout`j'"
|
||||
}
|
||||
tokenize "`plotVarLabels1'"
|
||||
}
|
||||
|
||||
tempname b V parmData varData
|
||||
|
||||
matrix parmData = J( 1, 300, 0 )
|
||||
matrix varData = J( 300, 300, 0 )
|
||||
|
||||
forval i = 1/`maxmodels' {
|
||||
if `numorder`i'' != 0 {
|
||||
tempname outPlot`i' groupPct`i'
|
||||
if `numindep`i'' == 4 * `numorder`i'' + 1 + `numdropout`i'' {
|
||||
matrix outPlot`i' = J( 1 + `numindep`i'', 4 * `numorder`i'' + 1 + `numdropout`i'', . )
|
||||
}
|
||||
else {
|
||||
matrix outPlot`i' = J( `numindep`i'', 4 * `numorder`i'' + 1 + `numdropout`i'', . )
|
||||
}
|
||||
matrix groupPct`i' = J( 1, `numorder`i'', . )
|
||||
}
|
||||
}
|
||||
|
||||
capture program _traj, plugin using("traj.plugin")
|
||||
/*
|
||||
`risk3' `expos3' `tcov3'
|
||||
*/
|
||||
|
||||
plugin call _traj `var1' `indep1' `risk1' `weight1' `expos1' ///
|
||||
`tcov1' `outcome1' `dcov1' `obsmar1' ///
|
||||
`var2' `indep2' `risk2' `expos2' `tcov2' ///
|
||||
`var3' `indep3' ///
|
||||
`outMat' if `touse' `in', ///
|
||||
`model1' ///
|
||||
`numindep1' ///
|
||||
`numrisk1' ///
|
||||
`numweight1' ///
|
||||
`numexpos1' ///
|
||||
`numtcov1' ///
|
||||
`plottcov1_len' ///
|
||||
`numorder1' ///
|
||||
"`min1'" ///
|
||||
"`max1'" ///
|
||||
`numiorder1' ///
|
||||
`numrorder1' ///
|
||||
`numdropout1' ///
|
||||
`numdcov1' ///
|
||||
`numobsmar1' ///
|
||||
"`omodel1'" ///
|
||||
`refgroup1' ///
|
||||
"`model2'" ///
|
||||
`numindep2' ///
|
||||
`numrisk2' ///
|
||||
`numexpos2' ///
|
||||
`numtcov2' ///
|
||||
`numorder2' ///
|
||||
"`min2'" ///
|
||||
"`max2'" ///
|
||||
`numiorder2' ///
|
||||
`refgroup2' ///
|
||||
"`model3'" ///
|
||||
`numindep3' ///
|
||||
`numorder3' ///
|
||||
"`min3'" ///
|
||||
"`max3'" ///
|
||||
`numiorder3' ///
|
||||
`multgroups' ///
|
||||
`traj_start_len' ///
|
||||
`itdetail' ///
|
||||
`ittrace' ///
|
||||
`itnovar' ///
|
||||
`oosprobs'
|
||||
|
||||
ereturn clear
|
||||
|
||||
local np : word count `outvars'
|
||||
|
||||
matrix `b' = parmData[1,1..`np']
|
||||
matrix `V' = varData[1..`np', 1..`np']
|
||||
|
||||
mat colnames `b' = `outvars'
|
||||
mat rownames `V' = `outvars'
|
||||
mat colnames `V' = `outvars'
|
||||
|
||||
ereturn post `b' `V', e(`touse')
|
||||
ereturn local cmd "traj"
|
||||
|
||||
forval i = 1/`maxmodels' {
|
||||
if `numorder`i'' != 0 {
|
||||
mat colnames outPlot`i' = `plotVarLabels`i''
|
||||
ereturn scalar numGroups`i' = `numorder`i''
|
||||
ereturn matrix plot`i' = outPlot`i'
|
||||
ereturn matrix groupSize`i' = groupPct`i'
|
||||
}
|
||||
}
|
||||
|
||||
ereturn local cmdline `"traj `0'"'
|
||||
|
||||
end
|
||||
/* end of traj.ado */
|
204
Modules/ado/plus/t/traj.hlp
Normal file
204
Modules/ado/plus/t/traj.hlp
Normal file
@ -0,0 +1,204 @@
|
||||
{smcl}
|
||||
{* 14may2012}{...}
|
||||
{cmd:help traj}
|
||||
{hline}
|
||||
|
||||
{p 4 4 6}{hi: traj}: Fit the traj model{p_end}
|
||||
{p 4 4 6}{hi: {help trajplot}}: Plot the traj model results{p_end}
|
||||
|
||||
{marker s_Description}
|
||||
{title:Description}
|
||||
|
||||
{p 4 4 6}
|
||||
{cmd:traj} uses a discrete mixture model to model longitudinal data. This model allows for data
|
||||
grouping using different parameter values for each group distribution. Groupings may identify
|
||||
distinct subpopulations. Alternatively, groupings may represent components approximating an
|
||||
unknown (possibly complex) data distribution.{p_end}
|
||||
|
||||
{hline}
|
||||
|
||||
{title:Examples}
|
||||
|
||||
1:{help traj##s_1: Censored Normal Model}
|
||||
2.{help traj##s_2: Zero-Inflated Poisson Model}
|
||||
3.{help traj##s_3: Logistic Model}
|
||||
4.{help traj##s_4: Time-Stable Covariates for Group Membership}
|
||||
5.{help traj##s_5: Group Membership Probabilities from a Model with Time Stable Covariates}
|
||||
6.{help traj##s_6: Time-Varying Covariates Influencing Trajectory Paths}
|
||||
7.{help traj##s_7: Start Values}
|
||||
8.{help traj##s_8: Joint Trajectory Model}
|
||||
9.{help traj##s_9: Distal Outcome Model}
|
||||
10.{help traj##s_10: Wald Tests for Hypotheses Based on the Parameter Estimates}
|
||||
11.{help traj##s_11: Exposure Time / Sample Weights}
|
||||
12.{help traj##s_12: Dropout Model}
|
||||
|
||||
{hline}
|
||||
|
||||
{marker s_Syntax}
|
||||
{title:Syntax}
|
||||
|
||||
{p 6 8 6}
|
||||
{cmdab:traj} [{help if:{it:if}}]{cmd:, var(}{help varlist:{it:varlist}}{cmd:) indep(}{help varlist:{it:varlist}}{cmd:) model(}{it:modeltype}{cmd:) order(}{help numlist:{it:numlist}}{cmd:)} [additional options] {p_end}
|
||||
|
||||
{synoptset 20 tabbed}{...}
|
||||
{synopthdr}
|
||||
{synoptline}
|
||||
{syntab:Trajectory Variables}
|
||||
{synopt :{opt var(varlist)}}dependent variables, measured at different times or ages{p_end}
|
||||
{synopt :{opt indep(varlist)}}independent variables i.e. when the dependant variables were measured{p_end}
|
||||
|
||||
{syntab:Model}
|
||||
{synopt :{opt model(modeltype)}}probability distribution for the dependent variables: {opt cnorm}, {opt zip}, or {opt logit} {p_end}
|
||||
{synopt :{opt order(numlist)}}polynomial type (0=intercept, 1=linear, 2=quadratic, 3=cubic) for each group trajectory{p_end}
|
||||
{synopt :{opt min(#)}}minimum value for the censored normal model (required for cnorm){p_end}
|
||||
{synopt :{opt max(#)}}maximum value for the censored normal model (required for cnorm){p_end}
|
||||
{synopt :{opt iorder(numlist)}}optional polynomial type (0=intercept, 1=linear, 2=quadratic, 3=cubic) for the zero-inflation of each group{p_end}
|
||||
{synopt :{opt exposure(varlist)}}optional exposure variables for the zero-inflated Poisson model{p_end}
|
||||
{synopt :{opt weight(varname)}}optional sampling weight variable{p_end}
|
||||
|
||||
{syntab:Time-Stable Covariates for Group Membership}
|
||||
{synopt :{opt risk(varlist)}}covariates for the probability of group membership{p_end}
|
||||
{synopt :{opt refgroup(#)}}controls the reference group (default = 1) when the risk option is used{p_end}
|
||||
|
||||
{syntab:Time-Varying Covariates for Group Membership}
|
||||
{synopt :{opt tcov(varlist)}}time-varying covariates for each group trajectory{p_end}
|
||||
{synopt :{opt plottcov(matrix)}}optional values for plotting trajectories with time-varying covariates{p_end}
|
||||
|
||||
{syntab:Dropout Model}
|
||||
{synopt :{opt dropout(numlist)}}include logistic model of dropout probability per wave with 0 = constant rate,
|
||||
1 = depends on the previous response, 2 = depends on the two previous responses, for each group{p_end}
|
||||
{synopt :{opt dcov(varlist)}}optional lagged time-varying covariates for the dropout model{p_end}
|
||||
{synopt :{opt obsmar(varname)}}optional binary variable to mark which observations are to be included
|
||||
in the dropout model and those to be treated as missing at random. This variable = 1 for observations to
|
||||
be treated as data MAR (include completers) and = 0 for observations to be used for the modeled dropout{p_end}
|
||||
|
||||
{syntab:Distal Outcome Model}
|
||||
{synopt :{opt outcome(varname)}}a distal variable to be regressed on the probability of group membership{p_end}
|
||||
{synopt :{opt omodel(modeltype)}}probability distribution for the outcome variable: {opt normal}, {opt cnorm}, {opt zip}, or {opt logit} {p_end}
|
||||
{synopt :{opt ocov(varlist)}}optional covariates for the outcome model{p_end}
|
||||
|
||||
|
||||
{syntab:Joint Trajectory Model}
|
||||
|
||||
{syntab:The joint trajectory model uses the options shown above with a '2' suffix to specify the second model e.g. {opt model2(modeltype)} etc. See the {help traj##s_8:joint trajectories} example.}
|
||||
|
||||
{syntab:Other}
|
||||
{synopt :{opt start(matrix)}}parameter start values to override default start values{p_end}
|
||||
{synopt :{opt detail}}show minimization iterations for monitoring model fitting progress{p_end}
|
||||
|
||||
{marker s_1}
|
||||
{title:Example 1: Censored Normal Model}
|
||||
|
||||
{p 4 10 8}{stata "use http://www.andrew.cmu.edu/user/bjones/traj/data/montreal_sim.dta, clear"}{p_end}
|
||||
{p 4 10 8}{stata "traj, model(cnorm) var(qcp*op) indep(age*) order(1 3 2) min(0) max(10)"}{p_end}
|
||||
{p 4 10 8}{stata `"trajplot, xtitle("Age") ytitle("Opposition")"'}{p_end}
|
||||
{p 4 10 8}{stata `"list _traj_Group - _traj_ProbG3 if _n < 3, ab(12)"'}{p_end}
|
||||
|
||||
{marker s_2}
|
||||
{title:Example 2: Zero-Inflated Poisson Model}
|
||||
|
||||
{p 4 10 8}{stata "use http://www.andrew.cmu.edu/user/bjones/traj/data/anag1.dta, clear"}{p_end}
|
||||
{p 4 10 8}{stata "traj, model(zip) var(y*) indep(t*) order(2 0 2 2)"}{p_end}
|
||||
{p 4 10 8}{stata `"trajplot, xtitle("Scaled Age") ytitle("Annual Conviction Rate") ci"'}{p_end}
|
||||
|
||||
{marker s_3}
|
||||
{title:Example 3: Logistic Model}
|
||||
|
||||
{p 4 10 8}{stata "use http://www.andrew.cmu.edu/user/bjones/traj/data/cambrdge.dta, clear"}{p_end}
|
||||
{p 4 10 8}{stata "traj, model(logit) var(p1-p23) indep(tt1-tt23) order(3 3 3)"}{p_end}
|
||||
{p 4 10 8}{stata `"trajplot, xtitle("Scaled Age") ytitle("Prevalence")"'}{p_end}
|
||||
|
||||
{marker s_4}
|
||||
{title:Example 4: Time-Stable Covariates for Group Membership}
|
||||
|
||||
{p 4 10 8}{stata "use http://www.andrew.cmu.edu/user/bjones/traj/data/montreal_sim.dta, clear"}{p_end}
|
||||
{p 4 10 8}{stata "traj, model(cnorm) var(qcp*op) indep(age*) order(1 3 2) min(0) max(10) risk(scolmer scolper)"}{p_end}
|
||||
{p 4 10 8}{stata `"trajplot, xtitle("Age") ytitle("Opposition")"'}{p_end}
|
||||
|
||||
{marker s_5}
|
||||
{title:Example 5: Group Membership Probabilities from a Model with Time Stable Covariates}
|
||||
|
||||
{p 4 10 8}{stata "use http://www.andrew.cmu.edu/user/bjones/traj/data/anag1.dta, clear"}{p_end}
|
||||
{p 4 10 8}{stata "matrix strt = (-4.57, -7, 5.96, -1.38, -20.5, 25.4, -8.0, -4.37, 5.55, -1.52, -1.7, 0, 0, 0, 0, -1.7, 0, 0, 0, 0, -2.5, 0, 0, 0, 0)"}{p_end}
|
||||
{p 4 10 8}{stata "traj, model(zip) var(y*) indep(t*) order(0 2 2 2) risk(lowiq crimpar daring pbeh) start(strt)"}{p_end}
|
||||
{p 4 10 8}{stata "list lowiq - _traj_ProbG4 in 1/6, ab(12)"}{p_end}
|
||||
|
||||
{marker s_6}
|
||||
{title:Example 6: Time-Varying Covariates Influencing Trajectory Paths}
|
||||
|
||||
{p 4 10 8}{stata "use http://www.andrew.cmu.edu/user/bjones/traj/data/gang_data_sim.dta, clear"}{p_end}
|
||||
{p 4 10 8}{stata "matrix tc1 = (0, 0, 0, 0, 0, 0, 0)"}{p_end}
|
||||
{p 4 10 8}{stata "matrix tc2 = (0, 0, 0, 1, 1, 1, 1)"}{p_end}
|
||||
{p 4 10 8}{stata "traj, model(zip) var(bat*) indep(t*) tcov(gang*) order(2 2 2 2 2) plottcov(tc1)"}{p_end}
|
||||
{p 4 10 8}{stata `"trajplot, xtitle("Scaled Age") ytitle("Rate")"'}{p_end}
|
||||
{p 4 10 8}{stata "traj, model(zip) var(bat*) indep(t*) tcov(gang*) order(2 2 2 2 2) plottcov(tc2)"}{p_end}
|
||||
{p 4 10 8}{stata `"trajplot, xtitle("Scaled Age") ytitle("Rate")"'}{p_end}
|
||||
|
||||
{marker s_7}
|
||||
{title:Example 7: Start Values}
|
||||
|
||||
{p 4 10 8}{stata "use http://www.andrew.cmu.edu/user/bjones/traj/data/cambrdge.dta, clear"}{p_end}
|
||||
{p 4 10 8}{stata "matrix strt = ( -4.8, -15.5, 16.2, -4.5, -1.1, -4.5, 5.1, -1.3, 0, -.2, 66, 20, 7, 7 )"}{p_end}
|
||||
{p 4 10 8}{stata "traj , model(zip) var(x01-x23) indep(tt1-tt23) order(0 2 0 2) iorder(1) start(strt)"}{p_end}
|
||||
{p 4 10 8}{stata `"trajplot, ytitle("Offense Counts") xtitle("Scaled Age")"'}{p_end}
|
||||
|
||||
{marker s_8}
|
||||
{title:Example 8: Joint Trajectory Model}
|
||||
|
||||
{p 4 10 8}{stata "use http://www.andrew.cmu.edu/user/bjones/traj/data/montreal_sim.dta, clear"}{p_end}
|
||||
{p 4 10 8}{stata "traj , model(cnorm) var(qcp84op qcp88op qcp89op qcp90op qcp91op) indep(age1-age5) order(1 2 2) max(10) var2(qas91det qas92det qas93det qas94det qas95det) indep2(age3-age7) model2(zip) order2(2 2 2 2)"}{p_end}
|
||||
{p 4 10 8}{stata `"trajplot, ytitle("Opposition") xtitle("Age")"'}{p_end}
|
||||
{p 4 10 8}{stata `"trajplot, model(2) ytitle("Rate") xtitle("Age")"'}{p_end}
|
||||
|
||||
{marker s_9}
|
||||
{title:Example 9: Distal Outcome Model}
|
||||
|
||||
{p 4 10 8}{stata "use http://www.andrew.cmu.edu/user/bjones/traj/data/montreal_sim.dta, clear"}{p_end}
|
||||
{p 4 10 8}{stata "traj, model(cnorm) max(10) var(qcp84op qcp88op qcp89op qcp90op qcp91op) indep(age1-age5) order(0 2 2) outcome(nbp14) omodel(poisson)"}{p_end}
|
||||
{p 4 10 8}{stata `"trajplot, ytitle("Opposition") xtitle("Age")"'}{p_end}
|
||||
|
||||
{marker s_10}
|
||||
{title:Example 10: Wald Tests for Hypotheses Based on the Parameter Estimates}
|
||||
|
||||
{p 4 10 8}{stata "use http://www.andrew.cmu.edu/user/bjones/traj/data/anag1.dta, clear"}{p_end}
|
||||
{p 4 10 8}{stata "matrix strt = (-4.57, -7, 5.96, -1.38, -20.5, 25.4, -8.0, -4.37, 5.55, -1.52, -1.7, 0, 0, 0, 0, -1.7, 0, 0, 0, 0, -2.5, 0, 0, 0, 0)"}{p_end}
|
||||
{p 4 10 8}{stata "traj, model(zip) var(y*) indep(t*) order(0 2 2 2) risk(lowiq crimpar daring pbeh) start(strt)"}{p_end}
|
||||
{p 4 10 8}{stata "trajplot, ci"}{p_end}
|
||||
{p 4 10 8}{stata "testnl _b[lowiq2] = _b[lowiq3] = _b[lowiq4]"}{p_end}
|
||||
|
||||
{marker s_11}
|
||||
{title:Example 11: Exposure Time / Sample Weights}
|
||||
|
||||
{p 4 10 8}{stata "use http://www.andrew.cmu.edu/user/bjones/traj/data/weight_expos_sim.dta, clear"}{p_end}
|
||||
{p 4 10 8}{stata "traj, model(zip) var(g2 - g13) indep(t*) order(2 2) iorder(0 2) expos(e*) weight(wt50)"}{p_end}
|
||||
{p 4 10 8}{stata `"trajplot, xtitle("Age") ytitle("Annual Arrest Rate")"'}{p_end}
|
||||
|
||||
{marker s_12}
|
||||
{title:Example 12: Dropout Model}
|
||||
|
||||
{p 4 10 8}{stata "use http://www.andrew.cmu.edu/user/bjones/traj/data/panss.dta, clear"}{p_end}
|
||||
{p 4 10 8}{stata "traj, var(p1-p6) indep(t1-t6) model(cnorm) min(-999) max(999) order(3 3 0) risk(risper) dropout(2 2 2) dcov(risper risper risper risper risper risper)"}{p_end}
|
||||
{p 4 10 8}{stata `"trajplot, xtitle("Time (weeks)") ytitle("PANSS") ci"'}{p_end}
|
||||
{p 4 10 8}{stata `"trajplot, dropout xtitle("Time (weeks)") ytitle("Dropout probability")"'}{p_end}
|
||||
|
||||
{title:Author}
|
||||
|
||||
{p 4 4 6}Bobby L. Jones{p_end}
|
||||
{p 4 4 6}bjones@andrew.cmu.edu{p_end}
|
||||
|
||||
{p 4 4 6}based on work with Daniel S. Nagin.{p_end}
|
||||
|
||||
|
||||
{title:Web-page}
|
||||
|
||||
{p 4 4 6}http://www.andrew.cmu.edu/user/bjones/{p_end}
|
||||
|
||||
|
||||
{title:References}
|
||||
|
||||
{p 4 4 6}Jones BL, Nagin DS, Roeder K. 2001. A SAS procedure based on mixture models for estimating developmental trajectories. Sociological Methods & Research 29:374-393{p_end}
|
||||
|
||||
{p 4 4 6}Jones BL, Nagin DS. 2007. Advances in group-based trajectory modeling and an SAS procedure for estimating them. Sociological Methods & Research 35:542-571{p_end}
|
||||
|
||||
{p 4 4 6}Nagin D. 2005. Group-Based Modeling of Development. Cambridge, MA: Harvard Univ. Press{p_end}
|
||||
{smcl}
|
BIN
Modules/ado/plus/t/traj.plugin
Normal file
BIN
Modules/ado/plus/t/traj.plugin
Normal file
Binary file not shown.
90
Modules/ado/plus/t/trajplot.ado
Normal file
90
Modules/ado/plus/t/trajplot.ado
Normal file
@ -0,0 +1,90 @@
|
||||
*! traj Oct 09, 2013 Bobby L Jones
|
||||
|
||||
program trajplot
|
||||
version 9
|
||||
syntax ,[ model(integer 1) xlabel(str) ylabel(str) xtitle(str) ytitle(str) ///
|
||||
legendLabels(str) CI NOLEGEND DROPOUT ]
|
||||
preserve
|
||||
|
||||
tempname A plotVarNames
|
||||
capture confirm matrix e(plot`model')
|
||||
if _rc != 0 {
|
||||
display as error "plot data not found"
|
||||
exit _rc
|
||||
}
|
||||
|
||||
if "`dropout'" == "dropout" {
|
||||
if "`ci'" == "ci" {
|
||||
display "ci not supported for dropout probability"
|
||||
local ci = ""
|
||||
}
|
||||
}
|
||||
|
||||
mat Piv = e(groupSize`model')
|
||||
mat A = e(plot`model')
|
||||
svmat A, names(col)
|
||||
|
||||
local ng = e(numGroups`model')
|
||||
local plotCmd = " "
|
||||
local orderTxt = " "
|
||||
|
||||
forvalues i = 1/`ng' {
|
||||
local orderTxt "`orderTxt' `i'"
|
||||
local pi`i' : display %4.1f round( el( Piv, 1, `i' ), .1 )
|
||||
if "`dropout'" == "dropout" {
|
||||
local plotCmd "`plotCmd' (line Dropout`i' trajT, lwidth(thick))"
|
||||
}
|
||||
else {
|
||||
local plotCmd "`plotCmd' (line Est`i' trajT, lwidth(thick))"
|
||||
}
|
||||
local label`i' "`i' `pi`i''%"
|
||||
}
|
||||
|
||||
if "`ci'" == "ci" {
|
||||
forvalues i = 1/`ng' {
|
||||
local plotCmd "`plotCmd' (scatter Avg`i' trajT, mstyle(p`i'))"
|
||||
local plotCmd "`plotCmd' (line L95`i' trajT, lpattern(dash) lcolor(black))"
|
||||
local plotCmd "`plotCmd' (line U95`i' trajT, lpattern(dash) lcolor(black))"
|
||||
}
|
||||
}
|
||||
else {
|
||||
forvalues i = 1/`ng' {
|
||||
if "`dropout'" == "dropout" {
|
||||
local plotCmd "`plotCmd' (scatter Dropout`i' trajT, mstyle(p`i'))"
|
||||
}
|
||||
else {
|
||||
local plotCmd "`plotCmd' (scatter Avg`i' trajT, mstyle(p`i'))"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if "`nolegend'" == "nolegend" {
|
||||
local plotCmd "`plotCmd', ytitle(`ytitle') xtitle(`xtitle') yscale(titlegap(*5)) xscale(titlegap(*5)) legend(off) ylabel(`ylabel') xlabel(`xlabel') scale(1.2)"
|
||||
}
|
||||
else {
|
||||
local plotCmd "`plotCmd' ,legend(ring(1) cols(2) pos(6) order(`"`orderTxt'"') "
|
||||
}
|
||||
|
||||
|
||||
if "`legendLabels'" != "" & "`nolegend'" == "" {
|
||||
local plotCmd "`plotCmd' `legendLabels' )"
|
||||
}
|
||||
|
||||
if "`legendLabels'" == "" & "`nolegend'" == "" {
|
||||
local plotCmd "`plotCmd' label(1 "`label1'") label(2 "`label2'") label(3 "`label3'") "
|
||||
local plotCmd "`plotCmd' label(4 "`label4'") label(5 "`label5'") label(6 "`label6'") "
|
||||
local plotCmd "`plotCmd' label(7 "`label7'") label(8 "`label8'") label(9 "`label9'") "
|
||||
local plotCmd "`plotCmd' label(10 "`label10'") label(11 "`label11'") label(12 "`label12'") "
|
||||
local plotCmd "`plotCmd' label(14 "`label14'") label(15 "`label15'") label(16 "`label16'") )"
|
||||
}
|
||||
|
||||
if "`nolegend'" != "nolegend" {
|
||||
local plotCmd "`plotCmd' ytitle(`ytitle') xtitle(`xtitle') ylabel(`ylabel') xlabel(`xlabel') yscale(titlegap(*5)) xscale(titlegap(*5)) scale(1.2)"
|
||||
}
|
||||
|
||||
twoway `plotCmd'
|
||||
|
||||
restore
|
||||
|
||||
end
|
||||
/* end of trajplot.ado */
|
31
Modules/ado/plus/t/trajplot.hlp
Normal file
31
Modules/ado/plus/t/trajplot.hlp
Normal file
@ -0,0 +1,31 @@
|
||||
{smcl}
|
||||
{* 10apr2012}{...}
|
||||
{cmd:help trajplot}
|
||||
{hline}
|
||||
|
||||
{marker s_Description}
|
||||
{title:Description}
|
||||
|
||||
{p 4 4 6}
|
||||
{cmd:trajplot} supports plotting of the {help traj} model results.
|
||||
|
||||
{hline}
|
||||
|
||||
{marker s_Syntax}
|
||||
{title:Syntax}
|
||||
|
||||
{p 6 8 6}
|
||||
{cmdab:trajplot} [{cmd:,} {it:options}] {p_end}
|
||||
|
||||
{synoptset 20 tabbed}{...}
|
||||
{synopthdr}
|
||||
{synoptline}
|
||||
{synopt :{opt xtitle(xtitle)}}text for x-axis{p_end}
|
||||
{synopt :{opt ytitle(ytitle)}}text for y-axis{p_end}
|
||||
{synopt :{opt xlabel(xlabel)}}x-axis control, see {help axis_label_options}{p_end}
|
||||
{synopt :{opt ylabel(ylabel)}}y-axis control, see {help axis_label_options}{p_end}
|
||||
{synopt :{opt ci}}include 95% confidence intervals{p_end}
|
||||
{synopt :{opt dropout}}plot dropout probabilities{p_end}
|
||||
{synopt :{opt nolegend}}suppress legend on plot{p_end}
|
||||
|
||||
{smcl}
|
56
Modules/ado/plus/t/trnclist.ado
Normal file
56
Modules/ado/plus/t/trnclist.ado
Normal file
@ -0,0 +1,56 @@
|
||||
program def trnclist, rclass
|
||||
*! NJC 1.2.0 29 June 2000
|
||||
* NJC 1.1.0 7 June 2000
|
||||
* NJC 1.0.0 3 March 2000
|
||||
version 6.0
|
||||
gettoken list 0 : 0, parse(",")
|
||||
if "`list'" == "" | "`list'" == "," {
|
||||
di in r "nothing in list"
|
||||
exit 198
|
||||
}
|
||||
syntax , [ Length(numlist int >0) Number(numlist int >0) /*
|
||||
*/ Global(str) Noisily ]
|
||||
|
||||
if "`length'`number'" == "" {
|
||||
di in r "nothing to do?"
|
||||
exit 198
|
||||
}
|
||||
else if "`length'" != "" & "`number'" != "" {
|
||||
di in r "choose between length( ) and number( ) options"
|
||||
exit 198
|
||||
}
|
||||
|
||||
if length("`global'") > 8 {
|
||||
di in r "global name must be <=8 characters"
|
||||
exit 198
|
||||
}
|
||||
|
||||
if "`length'" != "" {
|
||||
if `length' > 80 {
|
||||
di in r "cannot handle word length > 80"
|
||||
exit 498
|
||||
}
|
||||
}
|
||||
|
||||
tokenize `list'
|
||||
|
||||
if "`length'" != "" {
|
||||
while "`1'" != "" {
|
||||
local 1 = substr("`1'",1,`length')
|
||||
local newlist "`newlist'`1' "
|
||||
mac shift
|
||||
}
|
||||
}
|
||||
else {
|
||||
while "`1'" != "" {
|
||||
local 1 = substr("`1'",1,length("`1'")-`number')
|
||||
local newlist "`newlist'`1' "
|
||||
mac shift
|
||||
}
|
||||
}
|
||||
|
||||
if "`noisily'" != "" { di "`newlist'" }
|
||||
if "`global'" != "" { global `global' "`newlist'" }
|
||||
return local list `newlist'
|
||||
end
|
||||
|
2
Modules/ado/plus/t/trnclist.hlp
Normal file
2
Modules/ado/plus/t/trnclist.hlp
Normal file
@ -0,0 +1,2 @@
|
||||
.h listutil
|
||||
|
Reference in New Issue
Block a user