Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • type mismatch error without string and numeric variables?

    Hi all,

    Here is what I am hoping is an easy issue to solve. I want to use strmst2 to calculate restricted mean survival time, both unadjusted and adjusted.

    The unadjusted command works fine:
    strmst2 ccpvnon, tau(5) reference(0)

    The command for adjusted RMST however, does not.

    strmst2 ccpvnon, tau(5) reference(0) covariates(bmi)

    Number of observations for analysis = 147

    The truncation time: tau = 5 was specified.
    Note: adjusted analysis may take a few minutes to run...

    Model summary (difference of RMST)
    ----------------------------------------------------------------------------
    | Coef. Std. Err. z P>|z| [95% Conf. Interval]
    ---------------+------------------------------------------------------------
    intercept | type mismatch
    r(109);


    I'm not sure I understand why there is a type mismatch here? None of my variables is a string, all are numeric. Could it be that all of the numeric variables need to be similarly stored? Somare are byte, float, int, etc. I'm working in stata 16. I've uninstalled and re-installed strmst2 and tried the same commands in a prior version of this data set with the same issue.

    Thanks!

  • #2
    I don't see anything in the main ado file that produces this error message; you should -set trace on- to find the error; you may want to change the default tracedepth; see
    Code:
    help trace

    Comment


    • #3
      Thanks!

      Here's the output preceding the error. I'm not sure what to make of the code to be honest. There is quite a bit of code that precedes this.

      Model summary (difference of RMST)
      - di in smcl in gr "{hline 15}{c TT}{hline 60}" _n " " _col(16) "{c |}" _col(
      > 20) "Coef." _col(27) "Std. Err." _col(41) "z" _col(46) "P>|z|" _col(54) "[$level%
      > Conf. Interval]"
      = di in smcl in gr "{hline 15}{c TT}{hline 60}" _n " " _col(16) "{c |}" _col(
      > 20) "Coef." _col(27) "Std. Err." _col(41) "z" _col(46) "P>|z|" _col(54) "[95% Conf
      > . Interval]"
      ----------------------------------------------------------------------------
      | Coef. Std. Err. z P>|z| [95% Conf. Interval]
      - di in smcl in gr "{hline 15}{c +}{hline 60}"
      ---------------+------------------------------------------------------------
      - local npar=rowsof(beta0)
      - forvalues p=1(1)`npar' {
      = forvalues p=1(1)3 {
      - di in smcl in gr %11s word("$covariates2",`p') _col(15) " {c |}" in ye _col(18) %7
      > .3f el(rmstdiff,`p',1) _col(26) %9.3f el(rmstdiff,`p',2) _col(38) %5.2f el(rmstdif
      > f,`p',3) _col(46) %5.3f el(rmstdiff,`p',4) _col(54) %7.3f el(rmstdiff,`p',5) _col(
      > 66) %7.3f el(rmstdiff,`p',6)
      = di in smcl in gr %11s word("intercept _Iccpvnon_1 bmi",1) _col(15) " {c |}" in ye
      > _col(18) %7.3f el(rmstdiff,1,1) _col(26) %9.3f el(rmstdiff,1,2) _col(38) %5.2f el(
      > rmstdiff,1,3) _col(46) %5.3f el(rmstdiff,1,4) _col(54) %7.3f el(rmstdiff,1,5) _col
      > (66) %7.3f el(rmstdiff,1,6)
      intercept | type mismatch
      }
      di in smcl in gr "{hline 15}{c BT}{hline 60}"
      if "`rmtl'"=="rmtl" {
      local esttypes rmstratio rmtlratio
      }
      else {
      local esttypes rmstratio
      }
      foreach e of local esttypes {
      if "`e'"=="rmstratio" {
      di _n in gr "Model summary (ratio of RMST)"
      }
      if "`e'"=="rmtlratio" {
      di _n in gr "Model summary (ratio of time-lost)"
      }
      di in smcl in gr "{hline 15}{c TT}{hline 72}" _n " " _col(16) "{c |}" _col(
      > 20) "Coef." _col(27) "Std. Err." _col(41) "z" _col(46) "P>|z|" _col(54) "exp(Coef.
      > )" _col(66) "[$level% Conf. Interval]"
      di in smcl in gr "{hline 15}{c +}{hline 72}"
      local npar=rowsof(beta0)
      forvalues p=1(1)`npar' {
      di in smcl in gr %11s word("$covariates2",`p') _col(15) " {c |}" in ye _col(18) %7
      > .3f el(`e',`p',1) _col(26) %9.3f el(`e',`p',2) _col(38) %5.2f el(`e',`p',3) _col(4
      > 6) %5.3f el(`e',`p',4) _col(56) %7.3f el(`e',`p',5) _col(65) %7.3f el(`e',`p',6) _
      > col(78) %7.3f el(`e',`p',7)
      }
      di in smcl in gr "{hline 15}{c BT}{hline 72}"
      }
      local esttype rmtlratio rmstratio rmstdiff
      foreach e of local esttype {
      return matrix `e'adj = `e'
      return matrix `e'cov = `e'cov
      }
      return scalar tau = $tau
      return scalar reference = $reference
      }
      -------------------------------------------------------------------- end strmst2 ---

      Comment


      • #4
        Hi,

        I have a similar problem with strmst2. It works fine when I do an unadjusted calculation but when I do an adjusted calculation with covariates I get the error:

        matrix A would be of mixed type
        When creating A=(...), the variables inside the parentheses must all be real or all be
        string. If numeric constants appear inside the parentheses, any variables that also
        appear must be numeric.
        r(109);

        All variabels are real. I use Stata/MP 16.1 on a MacBook Pro but I have also tried with Stata/IC 15.1 with the same result.


        I have also "set trace on" like Eric Nolley above. He missed the error code in red a bit above the output code he sent:

        ---------------------------------------------------------------------------------------------------------------- begin unab ---
        - version 6
        - gettoken user 0: 0, parse(" :")
        - gettoken colon 0: 0, parse(" :")
        - if `"`colon'"' != ":" { error 198 }
        = if `":"' != ":" { error 198 }
        - syntax [varlist(default=empty)] [, MIN(integer 1) MAX(integer 120000) NAME(string)]
        - c_local `user' `varlist'
        = c_local _parse_varlist AbnormalCardio Abnormalresp Abnormalgastrointest AbnormalCNS AbnormalGenitourinary AbnormalSkin Abnorm
        > alMuscoloskel Abnormalother Abnormalotherspecify A1 A2 A3
        - local n : word count `varlist'
        = local n : word count AbnormalCardio Abnormalresp Abnormalgastrointest AbnormalCNS AbnormalGenitourinary AbnormalSkin Abnormal
        > Muscoloskel Abnormalother Abnormalotherspecify A1 A2 A3
        - if `n'>=`min' & `n'<=`max' { exit }
        = if 12>=1 & 12<=120000 { exit }
        ------------------------------------------------------------------------------------------------------------------ end unab ---
        matrix A would be of mixed type
        When creating A=(...), the variables inside the parentheses must all be real or all be string. If numeric constants appear inside
        the parentheses, any variables that also appear must be numeric.

        ----------------------------------------------------------------------------------------------------------------- end putmata ---
        mata: mata_est(A, gamma, beta0)
        local zscore = invnorm(1 - (100-$level)/2/100)
        if "$esttype"=="rmstdiff" {
        mata : st_matrix("cilow", st_matrix("beta0") :- `zscore' :* st_matrix("se0"))
        mata : st_matrix("cihigh", st_matrix("beta0") :+ `zscore' :* st_matrix("se0"))
        }
        if "$esttype"=="rmstratio" | "$esttype"=="rmtlratio" {
        mata : st_matrix("r0", exp(st_matrix("beta0")))
        mata : st_matrix("cilow", exp(st_matrix("beta0") :- `zscore' :* st_matrix("se0")))
        mata : st_matrix("cihigh", exp(st_matrix("beta0") :+ `zscore' :* st_matrix("se0")))
        }
        return matrix beta0=beta0
        return matrix se0 = se0
        return matrix z0 = z0
        return matrix p0 = p0
        return matrix covariance = covariance
        if "$esttype"=="rmstratio" | "$esttype"=="rmtlratio" {
        return matrix r0 = r0
        }
        return matrix cilow = cilow
        return matrix cihigh = cihigh
        drop A1 A2 A3 gamma1 gamma2 gamma3
        }
        ---------------------------------------------------------------------------------------------------------- end strmst2.rmst2reg ---
        restore
        matrix beta0 = r(beta0)
        matrix se0 = r(se0)
        matrix z0 = r(z0)
        matrix p0 = r(p0)
        matrix covariance = r(covariance)
        if "`e'"=="rmstratio" | "`e'"=="rmtlratio" {
        matrix r0 = r(r0)
        }
        matrix cilow = r(cilow)
        matrix cihigh = r(cihigh)
        if "`e'"=="rmstdiff" {
        matrix combined = beta0, se0, z0, p0, cilow, cihigh
        matrix roweq combined=""
        matrix rownames combined = $covariates2
        matrix colnames combined = Coefficient StdErr z p Lower$level% Upper$level%
        }
        if "`e'"=="rmstratio" | "`e'"=="rmtlratio" {
        matrix combined = beta0, se0, z0, p0, r0, cilow, cihigh
        matrix roweq combined=""
        matrix rownames combined = $covariates2
        matrix colnames combined = Coefficient StdErr z p exp(Coef) Lower$level% Upper$level%
        }
        return matrix `e'adj = combined
        matrix rownames covariance = $covariates2
        matrix colnames covariance = $covariates2
        return matrix `e'cov = covariance
        }
        }
        --------------------------------------------------------------------------------------------------------- end strmst2.rmst2regRUN ---
        local esttype rmtlratio rmstratio rmstdiff
        foreach e of local esttype {
        matrix `e' = r(`e'adj)
        matrix `e'cov = r(`e'cov)
        }
        matrix combinede = (rmstdiff[2..2,1..1] \ rmstratio[2..2,5..5] \ rmtlratio[2..2,5..5] )
        matrix combinedl = (rmstdiff[2..2,5..5] \ rmstratio[2..2,6..6] \ rmtlratio[2..2,6..6] )
        matrix combinedu = (rmstdiff[2..2,6..6] \ rmstratio[2..2,7..7] \ rmtlratio[2..2,7..7] )
        matrix combinedp = (rmstdiff[2..2,4..4] \ rmstratio[2..2,4..4] \ rmtlratio[2..2,4..4] )
        matrix outadj=combinede, combinedl, combinedu, combinedp
        matrix rownames outadj = RMSTdiff RMSTratio RMTLratio
        matrix colnames outadj = Estimate Lower$level% Upper$level% P
        di _n in gr "Model summary (difference of RMST)"
        di in smcl in gr "{hline 15}{c TT}{hline 60}" _n " " _col(16) "{c |}" _col(20) "Coef." _col(27) "Std. Err." _col(41) "z" _col(
        > 46) "P>|z|" _col(54) "[$level% Conf. Interval]"
        di in smcl in gr "{hline 15}{c +}{hline 60}"
        local npar=rowsof(beta0)
        forvalues p=1(1)`npar' {
        di in smcl in gr %11s word("$covariates2",`p') _col(15) " {c |}" in ye _col(18) %7.3f el(rmstdiff,`p',1) _col(26) %9.3f el(rmstdiff,`
        > p',2) _col(38) %5.2f el(rmstdiff,`p',3) _col(46) %5.3f el(rmstdiff,`p',4) _col(54) %7.3f el(rmstdiff,`p',5) _col(66) %7.3f el(rmstdiff,
        > `p',6)
        }
        di in smcl in gr "{hline 15}{c BT}{hline 60}"
        if "`rmtl'"=="rmtl" {
        local esttypes rmstratio rmtlratio
        }
        else {
        local esttypes rmstratio
        }
        foreach e of local esttypes {
        if "`e'"=="rmstratio" {
        di _n in gr "Model summary (ratio of RMST)"
        }
        if "`e'"=="rmtlratio" {
        di _n in gr "Model summary (ratio of time-lost)"
        }
        di in smcl in gr "{hline 15}{c TT}{hline 72}" _n " " _col(16) "{c |}" _col(20) "Coef." _col(27) "Std. Err." _col(41) "z" _col(
        > 46) "P>|z|" _col(54) "exp(Coef.)" _col(66) "[$level% Conf. Interval]"
        di in smcl in gr "{hline 15}{c +}{hline 72}"
        local npar=rowsof(beta0)
        forvalues p=1(1)`npar' {
        di in smcl in gr %11s word("$covariates2",`p') _col(15) " {c |}" in ye _col(18) %7.3f el(`e',`p',1) _col(26) %9.3f el(`e',`p',2) _col
        > (38) %5.2f el(`e',`p',3) _col(46) %5.3f el(`e',`p',4) _col(56) %7.3f el(`e',`p',5) _col(65) %7.3f el(`e',`p',6) _col(78) %7.3f el(`e',`
        > p',7)
        }
        di in smcl in gr "{hline 15}{c BT}{hline 72}"
        }
        local esttype rmtlratio rmstratio rmstdiff
        foreach e of local esttype {
        return matrix `e'adj = `e'
        return matrix `e'cov = `e'cov
        }
        return scalar tau = $tau
        return scalar reference = $reference
        }
        -------------------------------------------------------------------- end strmst2 ---




        Comment


        • #5

          Maybe variable abbreviation is causing problems. Try again after
          Code:
          set varabbrev off

          Comment


          • #6
            Hi again,
            Now I have identified the problem by checking the output above. In my dataset I had some variables that started with a big letter A. Even if I did not use it in the strmst2 command it caused the problem. It is the mata-call: "putmata A=(A*) gamma=(gamma*), replace omitmissing" in strmst2 that incorrectly use mý variables starting with "A". I will post what I have found to the authors of strmst2 and hopefully they can make a correction to strmst2. Meanwhile the solution is to rename variables starting with "A" or delete them.

            Comment


            • #7
              Thank you Bjarte, for the suggestion but it I just got an other error: "variable beta0 not found"

              Comment


              • #8

                The - strmst2- seems to rely on variable abbreviation which was the cause of your original problem. Programs should not have this "property".
                Code:
                clear
                sysuse auto
                reg weight length
                
                set varabbrev off
                
                * strmst2 lines 458 ...
                
                matrix beta0=e(b)
                matrix beta0 = beta0'
                svmat beta0, names(beta0)  
                putmata beta0=beta0, replace omitmissing
                
                  
                * variable beta0 not found
                * r(111);
                 
                set varabbrev on
                
                putmata beta0=beta0, replace omitmissing
                Last edited by Bjarte Aagnes; 12 Aug 2020, 06:39.

                Comment

                Working...
                X