Skip to content

Commit 727da83

Browse files
committed
New release
1 parent a220993 commit 727da83

12 files changed

Lines changed: 1151 additions & 11 deletions

build/buildrelease.do

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Package files for new release
2-
local newversion 0_1_2
2+
local newversion 0_2_0
33
capture mkdir ../release/version_`newversion'
44
local fdir ../release/version_`newversion'/
55

build/buildrelease.log

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Notes:
2525
. do "buildrelease.do"
2626

2727
. // Package files for new release
28-
. local newversion 0_1_2
28+
. local newversion 0_2_0
2929

3030
. capture mkdir ../release/version_`newversion'
3131

@@ -34,38 +34,38 @@ Notes:
3434
.
3535
. // -modexpt-
3636
. copy ../modexpt/modexpt.ado `fdir', replace
37-
(file ../release/version_0_1_2/modexpt.ado not found)
37+
(file ../release/version_0_2_0/modexpt.ado not found)
3838

3939
. copy ../modexpt/modexpt.sthlp `fdir', replace
40-
(file ../release/version_0_1_2/modexpt.sthlp not found)
40+
(file ../release/version_0_2_0/modexpt.sthlp not found)
4141

4242
.
4343
. // -stdmest-
4444
. copy ../stdmest/stdmest.ado `fdir', replace
45-
(file ../release/version_0_1_2/stdmest.ado not found)
45+
(file ../release/version_0_2_0/stdmest.ado not found)
4646

4747
. copy ../stdmest/stdmest.sthlp `fdir', replace
48-
(file ../release/version_0_1_2/stdmest.sthlp not found)
48+
(file ../release/version_0_2_0/stdmest.sthlp not found)
4949

5050
.
5151
. // -stdmestm-
5252
. copy ../stdmestm/stdmestm.ado `fdir', replace
53-
(file ../release/version_0_1_2/stdmestm.ado not found)
53+
(file ../release/version_0_2_0/stdmestm.ado not found)
5454

5555
. copy ../stdmestm/stdmestm.sthlp `fdir', replace
56-
(file ../release/version_0_1_2/stdmestm.sthlp not found)
56+
(file ../release/version_0_2_0/stdmestm.sthlp not found)
5757

5858
.
5959
. // Mata library
6060
. capture erase `fdir'lstdmest.mlib
6161

6262
. copy ../lstdmest.mlib `fdir', replace
63-
(file ../release/version_0_1_2/lstdmest.mlib not found)
63+
(file ../release/version_0_2_0/lstdmest.mlib not found)
6464

6565
.
6666
. // README
6767
. copy ../README.md `fdir', replace
68-
(file ../release/version_0_1_2/README.md not found)
68+
(file ../release/version_0_2_0/README.md not found)
6969

7070
.
7171
end of do-file

release/stdmest-version_0_2_0.zip

26.1 KB
Binary file not shown.

release/version_0_2_0/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -stdmest-: Post-Estimation Predictions for Standardised Hierarchical Contrasts after -mestreg- and -uhtred- Models
2+
3+
-stdmest- is a Stata post-estimation command for hierarchical survival models fitted using -[mestreg](https://www.stata.com/manuals/memestreg.pdf)- or -[uhtred](https://github.com/RedDoorAnalytics/uhtred)-.
4+
5+
This command can be used to obtain predictions of, e.g., standardised survival probabilities while fixing posterior predictions of the random effects at any level of the hierarchy.
6+
7+
In other words, -stdmest- can obtain marginal predictions standardising across observed covariates (i.e., the fixed effects) while fixing predicted values of the random effects.
8+
Built-in post-estimation commands for -mestreg- and -uhtred- can do the opposite, i.e., marginalising over the random effects.
9+
10+
Three commands are provided by this package:
11+
12+
* `modexpt`, to export results (`e(b)`, `e(V)`) for fitted -mestreg- and -stmixed- models.
13+
This is useful to, e.g., use the R version of `stdmest`, which is available [here](https://github.com/RedDoorAnalytics/stdmest-r);
14+
15+
* `stdmest`, to perform regression standardisation while fixing random intercept values.
16+
Any number of random intercepts can be fixed using this command;
17+
18+
* `stdmestm`, to perform regression standardisation fixing one random intercept value while integrating over a second random intercept.
19+
For this, only three-level models (e.g., patients nested within surgeons, surgeons nested within hospitals) are supported.
20+
21+
## Installation
22+
23+
The development version of -stdmest- can be installed from this GitHub repository by typing the following in your Stata console:
24+
25+
```{stata}
26+
net install stdmest, from("https://raw.githubusercontent.com/RedDoorAnalytics/stdmest/main/")
27+
```
28+
29+
## References
30+
31+
* Gasparini, A., Crowther, M.J. & Schaffer, J.M. Standardized survival probabilities and contrasts between hierarchical units in multilevel survival models. BMC Med Res Methodol (2026). https://doi.org/10.1186/s12874-026-02782-8
306 KB
Binary file not shown.

release/version_0_2_0/modexpt.ado

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
*! version 0.0.1 Alessandro Gasparini 16Jul2024
2+
3+
program define modexpt
4+
// Version
5+
version 18
6+
7+
// Check that we run modexpt after mestreg or stmixed
8+
if ("`e(cmd2)'" != "mestreg") & ("`e(cmd2)'" != "stmixed") {
9+
display as error "This only works after fitting a model with {cmd: mestreg} or {cmd: stmixed}."
10+
exit 301
11+
}
12+
13+
// Syntax
14+
syntax , FILEName(string) [replace]
15+
16+
// Local names
17+
tempname b V
18+
19+
// Export e(b)
20+
capture putexcel set "`filename'", `replace' sheet("e(b)", replace)
21+
if _rc {
22+
display as error "File {cmd:`filename'} already exists; you might want to specify the {cmd:replace} option."
23+
exit 602
24+
}
25+
matrix `b' = e(b)
26+
putexcel A1 = matrix(`b'), names
27+
putexcel save
28+
29+
// Add e(V) in a separate Excel sheet
30+
matrix `V' = e(V)
31+
putexcel set "`filename'", modify sheet("e(V)", replace)
32+
putexcel A1 = matrix(`V')
33+
putexcel save
34+
35+
// Add estimation command in a separate Excel sheet
36+
putexcel set "`filename'", modify sheet("cmd", replace)
37+
putexcel A1 = "`e(cmd2)'"
38+
putexcel save
39+
40+
// Add cmdline in a separate Excel sheet
41+
putexcel set "`filename'", modify sheet("cmdline", replace)
42+
if "`e(cmd2)'" == "mestreg" {
43+
putexcel A1 = "`e(cmdline)'"
44+
}
45+
else {
46+
putexcel A1 = "`e(cmdline2)'"
47+
}
48+
putexcel save
49+
50+
// Add family/distribution in a separate Excel sheet
51+
putexcel set "`filename'", modify sheet("family", replace)
52+
if "`e(cmd2)'" == "mestreg" {
53+
putexcel A1 = "`e(distribution)'"
54+
}
55+
else {
56+
putexcel A1 = "`e(family1)'"
57+
}
58+
putexcel save
59+
60+
// If -mestreg- model, add parametrisation in a separate Excel sheet
61+
if "`e(cmd2)'" == "mestreg" {
62+
putexcel set "`filename'", modify sheet("frm", replace)
63+
putexcel A1 = "`e(frm2)'"
64+
putexcel save
65+
}
66+
67+
// If -stmixed- with distribution(rp), export stuff to rebuild the spline
68+
if ("`e(cmd2)'" == "stmixed") & ("`e(family1)'" == "rp") {
69+
putexcel set "`filename'", modify sheet("e(knots1)", replace)
70+
putexcel A1 = "`e(knots1)'"
71+
putexcel save
72+
//
73+
putexcel set "`filename'", modify sheet("e(orthog1)", replace)
74+
putexcel A1 = "`e(orthog1)'"
75+
putexcel save
76+
//
77+
tempname rcsrmat
78+
matrix `rcsrmat' = e(rcsrmat_1)
79+
putexcel set "`filename'", modify sheet("e(rcsrmat_1)", replace)
80+
putexcel A1 = matrix(`rcsrmat')
81+
putexcel save
82+
//
83+
}
84+
85+
// If -stmixed- model, export parameters labels
86+
if ("`e(cmd2)'" == "stmixed") {
87+
putexcel set "`filename'", modify sheet("e(cmplabels1)", replace)
88+
putexcel A1 = "`e(cmplabels1)'"
89+
putexcel save
90+
}
91+
92+
end
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{smcl}
2+
{* *! version 1.0.0}{...}
3+
{vieweralsosee "mestreg" "help mestreg"}{...}
4+
{vieweralsosee "stmixed" "help stmixed"}{...}
5+
{viewerjumpto "Syntax" "modexpt##syntax"}{...}
6+
{viewerjumpto "Description" "modexpt##description"}{...}
7+
{viewerjumpto "Options" "modexpt##options"}{...}
8+
{viewerjumpto "Examples" "modexpt##examples"}{...}
9+
{viewerjumpto "Author" "modexpt##author"}{...}
10+
11+
{synopt :{cmd: modexpt} {hline 2} Export estimation results of {cmd: mestreg} and {cmd: stmixed} models to an Excel file}
12+
13+
{marker syntax}{...}
14+
{title: Syntax}
15+
16+
{phang}
17+
Export results of {cmd: mestreg} and {cmd: stmixed} models to an Excel file:
18+
{p_end}
19+
20+
{phang2}
21+
{cmd: modexpt}, {opt filename(string)} [{opt replace}]
22+
{p_end}
23+
24+
{synoptset}{...}
25+
{marker options_table}{...}
26+
{synopthdr: Option}
27+
{synoptline}
28+
{synopt: {cmdab: filen:ame(}{it: string})}Name of the file to export results to{p_end}
29+
{synopt: {cmdab: replace}}Overwrite Excel file{p_end}
30+
{synoptline}
31+
32+
{pstd}See {helpb putexcel}, which is used under-the-hood, for more details.
33+
34+
{marker description}{...}
35+
{title: Description}
36+
37+
{pstd}
38+
{cmd: modexpt} can be used to export an Excel file with estimated coefficients and their variance-covariance matrix of {cmd: mestreg} and {cmd: stmixed} models.
39+
Specifically, {cmd: e(b)} and {cmd: e(V)} that are stored in {cmd: ereturn} by {cmd: mestreg} and {cmd: stmixed} are exported in separate tabs of the Excel file specified with {opt filename(string)}.
40+
Note that some ancillary information, such as the model distribution/family, are exported as well.
41+
42+
{marker options}{...}
43+
{title: Options}
44+
45+
{phang}
46+
{opt filename(string)} specifies the name of the Excel file to be used to export the estimation results after {cmd: mestreg} or {cmd: stmixed}.
47+
The name must be a string, potentially including the path to a location other than the working directory.
48+
{p_end}
49+
50+
{phang}
51+
{opt replace} overwrites the specified Excel file, if needed.
52+
53+
{marker examples}{...}
54+
{title: Examples}
55+
56+
{pstd}
57+
We start by replicating one of the examples from the {helpb mestreg} help file:
58+
59+
{phang}{stata webuse catheter: . webuse catheter}{p_end}
60+
{phang}{stata "mestreg age female || patient:, distribution(weibull)": . mestreg age female || patient:, distribution(weibull)}{p_end}
61+
62+
{pstd}
63+
Note that everything would work the same if we had fit a {cmd: stmixed} model instead.
64+
Then, we export the estimation results in a file named {cmd: test.xlsx}, located in the current working directory:
65+
66+
{phang}{stata modexpt, filename("test.xlsx"): . modexpt, filename("test.xlsx")}{p_end}
67+
68+
{pstd}
69+
If we were to run the above command again we would get an error, as the file already exists.
70+
We can overcome this by using the {opt replace} option:
71+
72+
{phang}{stata modexpt, filename("test.xlsx") replace: . modexpt, filename("test.xlsx") replace}{p_end}
73+
74+
{pstd}
75+
Finally, for {cmd: stmixed} models, we would replicate the above as:
76+
77+
{phang}{stata webuse catheter: . webuse catheter}{p_end}
78+
{phang}{stata "stmixed age female || patient:, distribution(weibull)": . stmixed age female || patient:, distribution(weibull)}{p_end}
79+
{phang}{stata modexpt, filename("test.xlsx"): . modexpt, filename("test.xlsx")}{p_end}
80+
81+
{marker author}{...}
82+
{title: Author}
83+
84+
{pstd}Alessandro Gasparini{p_end}
85+
{pstd}Red Door Analytics AB{p_end}
86+
{pstd}Stockholm, Sweden{p_end}
87+
{pstd}E-mail: {browse "mailto:alessandro.gasparini@reddooranalytics.se":alessandro.gasparini@reddooranalytics.se}.{p_end}
88+
89+
{phang}
90+
Please report any errors you may find, e.g., on {browse "https://github.com/RedDoorAnalytics/stdmest":GitHub} or by e-mail.
91+
{p_end}

0 commit comments

Comments
 (0)