Hello all: I have this wrapper to ereturn all relevant OS and median survival from the ssc program -stpm2- I have a single main variable I am modeling with all adjustment variables in a separate list in `adjust' below. I have a missing value in one of the adjust variables mvaf25. The programs stalls and ask me to exclude with an -if- statement to exclude the missing case, despite the -marksample- line which I thought would pick all main and adjustment variables with complete data. I have included parts of the program which I think are relevant. Sorry this is not a reproducible example. I have a parallel program for Cox HR and CI etc. with the same exact code structure with marksample has no issues there. Perhaps the issue is related to stpm2-generated new variables? The program runs fine with all non-missing variables or if manually delete casewise missing ones.
Error
Sample ereturned locals are below
Code:
cap program drop fpm50
program define fpm50, eclass
version 18.0
ereturn clear
qui count
ereturn local tot = `r(N)'
syntax varlist(numeric max=1) [if] ///
[, ADJust(namelist)] ///
[DOF(integer 3)] ///
[TEXT0(string asis)] ///
[TEXT1(string asis)] ///
[TEXT2(string asis)] ///
[unit(string)]
*-------------------------------------------
marksample touse
di "`unit'"
// Housekeeping
*--------------
cap drop _rcs* _d_* tt means* // Drops any variable created by prior stpm2
qui stdescribe // Grab exit time
local t = floor(`r(tr_max)') // Makes it an integer
local vlab: variable label `varlist' // Need for calls
local endash = ustrunescape("\u2013") // Need for calls
.(..spacing codes for return locals)
// Restrict the program to take binary variables
*-----------------------------------------------
qui levelsof `varlist' if(`touse'), local(lev)
scalar nt = `r(r)'
cap assert nt>2
if !_rc {
disp "There are `=nt' levels"
}
// Run the FPM model
*--------------------
set trace on
qui stpm2 `varlist' `adjust' if(`touse'), df(`dof') eform scale(h)
qui mat li r(table)
tempname a
mat `a' = r(table)
set trace off
// Calculate Somer's D explained variance
*------------------------------------------
qui str2d: `e(cmdline)' // Repeats the stpm2 and runs the Somer's D
local somd = int(r(r2)*100)
local somlow = int(r(r2ll)*100)
local somhigh = int(r(r2ul)*100)
// Gather HR, 95% and pvalue
*--------------------------
local b = string(`a'[1,1], "%09.1fc")
local l = string(`a'[5,1], "%09.1fc")
local u = string(`a'[6,1], "%09.1fc")
local p = `a'[4,1]
local n = e(N)
// Fix p-value formats
*---------------------
pvformat `p'
local pvalue = scalar(p)
local pfpm = "`pvalue'"
range tt 1 `t' `t'
foreach i of local lev {
qui predict means`i' if `touse', meansurv ci timevar(tt) at(`varlist' `i')
local os`i' = string(round(means`i'[`t'] * 100, 0.1), "%9.1f") + "%"
scalar fos`i' = round(means`i'[`t'], 0.01)
}
// Median survival frame
tempname med
frame create `med'
cap frame drop __00*
frame copy default `med'
frame `med'{
standsurv, atvars(med0 med1) at1(`varlist' 0) at2(`varlist' 1) centile(50) timevar(tt) ci
* Parametric median survival and CIs
*---------------------------------------
*** code for this
// Create e-display text for the HR
*---------------------------------
ereturn clear
ereturn needed locals...(here)
// Drop created vars
*---------------------
cap drop _rcs* _d_* tt means*
cls
end
Code:
fpm50 ep7, adjust(age70 mvaf25) unit(mos.) dof(4)
Code:
There are missing values for mvaf25 You can restrict using an if statement r(198);
Code:
---------------------------------------------------------------------------
Flexible Parametric model for OS, HR and Somer's D
--------------------------------------------------
Variable main : ep7 (EPI7 signature)
Adjusted for : age70 time0
Explained Variance : 7%
---------------------------------------------------------------------------
scalars:
e(fos0) = .21
e(fos1) = .07
macros:
e(os1) : "6.8%"
e(os0) : "21.4%"
e(callos01) : "21.4% vs. 6.8%; Pfpm < .001"
e(callos10) : "6.8% vs. 21.4%; Pfpm < .001"
e(somd) : "7% (95% CI: 2–14%)"
e(n) : "204"
e(u) : "2.5"
e(l) : "1.3"
e(b) : "1.8"
e(pfpm) : "< .001"
e(callhrp) : "HR = 1.8 [1.3–2.5]; Pfpm < .001; N = 204"
e(callhr) : "HR = 1.8 [1.3–2.5]; Pfpm < .001"
e(callmed01) : "9.1 mos. vs. 5.4 mos."
e(callmed10) : "5.4 mos. vs. 9.1 mos."
---------------------------------------------------------------------------

Comment