Announcement

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

  • Parameters in assert command must be positive

    Hello,

    I am using the assert command in a program that I wrote and I get the error message indicating false assertion:

    Code:
    local var1 -3.0
    local var2 -5.0
    local var3 -3.1
    
    program define test, rclass
            args var1 var2 var3
            assert `var1' < 0 & `var2' < 0 & `var3' <0
    end test
    .
    .
    .
    r(9);
    If, however, I flip the alligator clips to indicate that var1, var2, and var3 are positive in the assert command then the code runs fine. This is not what I want though as these variables should be negative as defined in the local macros. Is there a workaround for this?

  • #2
    I don't see anything wrong with your code, and I can't replicate your problem. It works just fine on my setup. Here's some example output:

    Code:
    . clear*
    
    . local var1 -3.0
    
    . local var2 -5.0
    
    . local var3 -3.1
    
    .
    . program define test, rclass
      1.         args var1 var2 var3
      2.         assert `var1' < 0 & `var2' < 0 & `var3' <0
      3. end test
    
    .
    . test `var1' `var2' `var3'
    
    .
    . local var2 5.0
    
    . test `var1' `var2' `var3'
    assertion is false
    r(9);
    I'm running Stata 16.1 MP 64-bit on a Windows 10 machine.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      I don't see anything wrong with your code, and I can't replicate your problem. It works just fine on my setup. Here's some example output:

      Code:
      . clear*
      
      . local var1 -3.0
      
      . local var2 -5.0
      
      . local var3 -3.1
      
      .
      . program define test, rclass
      1. args var1 var2 var3
      2. assert `var1' < 0 & `var2' < 0 & `var3' <0
      3. end test
      
      .
      . test `var1' `var2' `var3'
      
      .
      . local var2 5.0
      
      . test `var1' `var2' `var3'
      assertion is false
      r(9);
      I'm running Stata 16.1 MP 64-bit on a Windows 10 machine.
      Indeed the program runs fine in a vacuum. What I have noticed though is that the error appears when I combine it with the remainder of my code for reasons unbeknownst to me. I have removed it and the code runs because I don't think it actually affects any results and does not serve any purpose that I know of.

      Comment


      • #4
        So apparently you are using code written by someone else, and you don't understand what purpose the assert command serves, and you don't understand why it fails, so you will remove it to make your program run.

        Presumably the author included the assert command to guarantee that the three values are less than zero. The fact that the assert fails in the context of your program suggests that whatever var1, var2, and var3 represent (are they really just three constants, or are they variable names?) have been changed by your program such that at the point where the assert command is run, it fails.

        If the methodology implemented in the program assumes that the conditions in the assert command are met, then if the assumptions are not fulfilled it is possible that while the code doesn't fail the results you obtain are incorrect or inappropriate.

        Comment


        • #5
          Originally posted by William Lisowski View Post
          So apparently you are using code written by someone else, and you don't understand what purpose the assert command serves, and you don't understand why it fails, so you will remove it to make your program run.

          Presumably the author included the assert command to guarantee that the three values are less than zero. The fact that the assert fails in the context of your program suggests that whatever var1, var2, and var3 represent (are they really just three constants, or are they variable names?) have been changed by your program such that at the point where the assert command is run, it fails.

          If the methodology implemented in the program assumes that the conditions in the assert command are met, then if the assumptions are not fulfilled it is possible that while the code doesn't fail the results you obtain are incorrect or inappropriate.
          They are just (negative) constants that should in fact be negative. The issue is the assert command in conjunction with all of the other code outside of the program returns error r(9) if var1, var2, and var3 are asserted as < 0, but it runs fine otherwise (i.e. > 0). However, the assert command should not include (var1 >0, var2 > 0, and var3 >0).

          Comment


          • #6
            Then my point stands. The assert command fails which means that "all the other code outside of the program" apparently affects the values of those three "constants" - as Clyde's code in post #2 replaced the negative value of the constant in the local macro var2 with a positive value, which caused the assert command to fail.

            Again, the assert command is telling you that at the time it is run the "constants" contained in the local macros are not negative. Before the assert command add
            Code:
            display "var1 = `var1' and var2 = `var2' and var3 = `var3'"
            to see what it is you have. That should be your first reaction to an assert command failing - find out more about the things that caused it to fail.

            You have a problem that you need to understand and correct if you want to be confident in your results.

            Comment


            • #7
              For direct approach, and to be less cagey, why not post the entire program?

              Comment


              • #8
                I would like to second this kind request, and to extend the kind request to the other thread by Jack Chau as well
                https://www.statalist.org/forums/for...ext-from-xtgee

                These two mysteries Jack posed are killing me, I am dying to know what is happening here...

                Originally posted by Leonardo Guizzetti View Post
                For direct approach, and to be less cagey, why not post the entire program?

                Comment


                • #9
                  Hello everyone,

                  So here is the code that I am working with.

                  Code:
                  clear *
                  
                  *Generate multi-level data 
                  capture program drop swcrt
                  program define swcrt, rclass
                          args num_clus clussize intercept intrvcoeff timecoeff1 timecoeff2 timecoeff3 timecoeff4 timecoeff5 sigma_u3 sigma_error alpha
                          assert `num_clus' > 0 & `clussize' > 0 & `intercept' > 0 & `intrvcoeff' > 0 & `timecoeff1' > 0 & `timecoeff2' > 0 & `timecoeff3' > 0 & `timecoeff4' > 0 & `timecoeff5' > 0 & `sigma_u3' > 0 & `sigma_error' > 0 & `alpha' > 0
                      *Generate simulated multi—level data
                          qui
                                  clear
                                  set obs `num_clus'   
                                  qui gen cluster = _n
                                  qui gen group = 1+mod(_n-1,4)
                                  *Generate cluster-level errors
                                  qui gen u_3 = rnormal(0,`sigma_u3')   
                                  expand `clussize'
                                  bysort cluster: gen individual = _n
                                  *Set up time
                                  expand 6
                                  bysort cluster individual: gen time = _n-1 
                                  *Set up intervention variable
                                  gen intrv = (time>=group) 
                                  *Generate residual errors
                                  qui gen error = rnormal(0,`sigma_error') 
                                  *Generate outcome y
                                  qui gen y = `intercept' + `intrvcoeff'*intrv + `timecoeff1'*1.time + `timecoeff2'*2.time + `timecoeff3'*3.time + `timecoeff4'*4.time + `timecoeff5'*5.time + u_3 + error 
                      
                      *Fit multi-level model to simulated dataset
                      *xtset cluster 
                      *xtgee y intrv i.time, family(gaussian) link(identity) corr(exchangeable) 
                  
                      xtgeebcv y intrv i.time, cluster(cluster) family(gaussian) link(identity) corr(exchangeable) stderr(kc)
                          
                      *Return estimated effect size, bias, p-value, and significance dichotomy
                      tempname M
                      matrix `M' = r(table)
                      return scalar b = _b[intrv]
                      return scalar bias = _b[intrv] - `intrvcoeff'
                      return scalar p = `M'[1,4]
                      return scalar p_= (`M'[1,4] < `alpha') 
                      exit
                  end swcrt
                   
                  *Stepped-wedge specifications
                  local num_clus 3 6 9 18 36
                  local clussize 5 10 15 20 25 
                  *Model specifications
                  local intercept 17.87
                  local timecoeff1 -5.42
                  local timecoeff2 -5.72
                  local timecoeff3 -7.03
                  local timecoeff4 -6.13
                  local timecoeff5 -9.13
                  local intrvcoeff 5.00
                  local sigma_u3 25.77
                  local sigma_u2 120.62
                  local sigma_error 38.35
                  local alpha 0.05
                  local nrep 1000
                  
                  *Postfile to store results
                  tempname step
                  tempfile powerresults
                  capture postutil clear 
                  postfile `step' num_clus clussize intrvcoeff b p p_ bias using `powerresults.dta', replace 
                  *Loop over number of clusters
                  foreach c of local num_clus{
                      display as text "Number of clusters" as result "`c'"
                          foreach s of local clussize {
                              display as text "Cluster size" as result "`s'"
                                  forvalue i = 1/`nrep'{
                                      display as text "Iterations" as result `nrep'    
                                      quietly swcrt `num_clus' `clussize' `intercept' `intrvcoeff' `timecoeff1' `timecoeff2' `timecoeff3' `timecoeff4' `timecoeff5' `sigma_u3' `sigma_error' `alpha'
                                      post `step' (`c') (`s') (`intrvcoeff') (`r(b)') (`r(p)') (`r(p_)') (`r(bias)') 
                                  }
                  
                          }
                  
                  }        
                  postclose `step' 
                  
                  *Open results, calculate power
                  use `powerresults', clear 
                  
                  levelsof num_clus, local(num_clus)
                  levelsof clussize, local(clussize)
                  matrix drop _all
                  *Loop over combinations of clusters 
                  *Add power results to matrix
                  foreach c of local num_clus{
                      foreach s of local clussize{
                          quietly ci proportions p_ if num_clus == `c'  & clussize = `s'
                          local power `r(proportion)'
                          local power_lb `r(lb)'
                          local power_ub `r(ub)'
                          quietly ci mean bias if num_clus == `c' & clussize = `s'
                          local bias `r(mean)'
                          matrix M = nullmat(M) \ (`c', `s', `intrvcoeff', `power', `power_lb', `power_ub', `bias') 
                      }
                  }
                      
                  *Display the matrix
                  matrix colnames M = c s intrvcoeff power power_lb power_ub bias //Arguments should match those in the previous line to avoid conformability errors
                  matrix list M, noheader format(%3.2f)
                  The first issue highlighted deals with the assert command. Evidently the local macros for time are negative which is what I want and because of that I think the time parameters in the assert command should also be negative. However, when I set it to negative I get the aforementioned r(9) false assertion error.

                  The second issue is obtaining estimates from xtgeebcv where I get the "matrix operators that return matrices not allowed in this context" error. I did some troubleshooting for this and the entire code runs if I use xtset and xtgee, but I need the xtgeebcv for some of the options that it provides.

                  Comment


                  • #10
                    Can you -set trace on- and see what is generating the problem "matrix operators that return matrices not allowed in this context"?

                    Because I really cannot see anything in this part of the code that can possibly give rise to such error.

                    By trial and error I have figured out that Stata returns this error when the matrix operation that returns a scalar needs evaluation. E.g., even if the result of a matrix multiplication is a scalar, when I try to equate it to a scalar the named error message appears. But in your code you have reference only to the elements of a matrix.

                    Comment


                    • #11
                      Where you have
                      Code:
                      quietly swcrt `num_clus' `clussize' `intercept' `intrvcoeff' `timecoeff1' `timecoeff2' `timecoeff3' `timecoeff4' `timecoeff5' `sigma_u3' `sigma_error' `alpha'
                      you want
                      Code:
                      quietly swcrt `c' `s' `intercept' `intrvcoeff' `timecoeff1' `timecoeff2' `timecoeff3' `timecoeff4' `timecoeff5' `sigma_u3' `sigma_error' `alpha'
                      Easily discovered by preceding the command with
                      Code:
                      display `"swcrt `num_clus' `clussize' `intercept' `intrvcoeff' `timecoeff1' `timecoeff2' `timecoeff3' `timecoeff4' `timecoeff5' `sigma_u3' `sigma_error' `alpha' "'
                      and then reading
                      Code:
                      Number of clusters3
                      Cluster size5
                      Iterations1000
                      swcrt 3 6 9 18 36 5 10 15 20 25 17.87 5.00 -5.42 -5.72 -7.03 -6.13 -9.13 25.77 38.35 0.05 
                      assertion is false
                      r(9);
                      Last edited by William Lisowski; 03 Aug 2020, 14:54.

                      Comment


                      • #12
                        Originally posted by Joro Kolev View Post
                        Can you -set trace on- and see what is generating the problem "matrix operators that return matrices not allowed in this context"?

                        Because I really cannot see anything in this part of the code that can possibly give rise to such error.

                        By trial and error I have figured out that Stata returns this error when the matrix operation that returns a scalar needs evaluation. E.g., even if the result of a matrix multiplication is a scalar, when I try to equate it to a scalar the named error message appears. But in your code you have reference only to the elements of a matrix.
                        I was thinking that it is a bit odd considering I am only trying to get the coefficient like I would from other regression commands.

                        I put the set trace option on, but still got the same matrix operator error that I had initially. The trace is far too long to output here, but it ends with:

                        Code:
                        r(509);
                        
                        end of do-file
                        
                        r(509);
                        Looking up the definition of the error, I am confused because I am not actually trying to return any matrices, only the coefficient of the parameter.

                        error . . . . . . . . . . . . . . . . . . . . . . . . Return code 509
                        matrix operators that return matrices not allowed in this context
                        Expressions returning nonmatrices, such as those in generate
                        and replace, may use matrix functions returning scalars, such
                        as trace (A), but may not include subexpressions evaluating to
                        matrices, such as trace (A+B), which requires evaluating the
                        matrix expression A + B. (Such subexpressions are allowed in
                        the context of expressions returning matrices, such as those
                        in matrix.)

                        Last edited by CEdward; 03 Aug 2020, 16:15.

                        Comment


                        • #13
                          Originally posted by William Lisowski View Post
                          Where you have
                          Code:
                          quietly swcrt `num_clus' `clussize' `intercept' `intrvcoeff' `timecoeff1' `timecoeff2' `timecoeff3' `timecoeff4' `timecoeff5' `sigma_u3' `sigma_error' `alpha'
                          you want
                          Code:
                          quietly swcrt `c' `s' `intercept' `intrvcoeff' `timecoeff1' `timecoeff2' `timecoeff3' `timecoeff4' `timecoeff5' `sigma_u3' `sigma_error' `alpha'
                          Easily discovered by preceding the command with
                          Code:
                          display `"swcrt `num_clus' `clussize' `intercept' `intrvcoeff' `timecoeff1' `timecoeff2' `timecoeff3' `timecoeff4' `timecoeff5' `sigma_u3' `sigma_error' `alpha' "'
                          and then reading
                          Code:
                          Number of clusters3
                          Cluster size5
                          Iterations1000
                          swcrt 3 6 9 18 36 5 10 15 20 25 17.87 5.00 -5.42 -5.72 -7.03 -6.13 -9.13 25.77 38.35 0.05
                          assertion is false
                          r(9);
                          Indeed, this solved the issue! Thanks! So basically it was an issue with calling the program with the wrong arguments not so much the actual values of the parameters.

                          Comment


                          • #14
                            So basically it was an issue with calling the program with the wrong arguments not so much the actual values of the parameters.
                            Yes, which is why if Stata tells you that something is not as you expected it to be, the first step is to find out what it actually is, before assuming that a workaround is needed - beyond the obvious workaround of locating and correcting any programming errors. Had you displayed the values of your arguments you would have quickly seen where you went wrong, as I did. Had you shown real code instead of made up code which when tested turned out not to reproduce the problem, you might have had an answer 24 hours ago.

                            Comment


                            • #15
                              Many thanks William.

                              So I did some investigating into the other issue and my guess is that the error has something to do with the xtgeebcv command itself.

                              I generated the data for one iteration of my program like so

                              clear
                              input float(cluster group u_3 individual time intrv error y) byte(_x_1 _x_2 _x_3 _x_4 _x_5 _x_6 _x_7 _x_8) float(_intercept _newclustid)
                              1 1 .9338073 1 0 0 -57.79356 -38.98975 0 0 0 0 0 0 0 0 1 1
                              1 1 .9338073 1 1 1 -78.99837 -60.61456 0 1 0 0 0 0 0 1 1 1
                              1 1 .9338073 1 2 1 13.360435 31.44424 0 0 1 0 0 0 0 1 1 1
                              1 1 .9338073 1 3 1 -37.540363 -20.766556 0 0 0 1 0 0 0 1 1 1
                              1 1 .9338073 1 4 1 -1.0950085 16.578798 0 0 0 0 1 0 0 1 1 1
                              1 1 .9338073 1 5 1 -28.20212 -13.52831 0 0 0 0 0 1 0 1 1 1
                              1 1 .9338073 2 0 0 6.909073 25.71288 0 0 0 0 0 0 0 0 1 1
                              1 1 .9338073 2 1 1 -69.08335 -50.69954 0 1 0 0 0 0 0 1 1 1
                              1 1 .9338073 2 2 1 12.171906 30.255714 0 0 1 0 0 0 0 1 1 1
                              1 1 .9338073 2 3 1 -6.224349 10.549458 0 0 0 1 0 0 0 1 1 1
                              1 1 .9338073 2 4 1 -88.0648 -70.39099 0 0 0 0 1 0 0 1 1 1
                              1 1 .9338073 2 5 1 -6.406471 8.267337 0 0 0 0 0 1 0 1 1 1
                              1 1 .9338073 3 0 0 60.65072 79.45453 0 0 0 0 0 0 0 0 1 1
                              1 1 .9338073 3 1 1 -50.71146 -32.327652 0 1 0 0 0 0 0 1 1 1
                              1 1 .9338073 3 2 1 -72.14864 -54.06483 0 0 1 0 0 0 0 1 1 1
                              1 1 .9338073 3 3 1 35.13123 51.90504 0 0 0 1 0 0 0 1 1 1
                              1 1 .9338073 3 4 1 3.789009 21.462816 0 0 0 0 1 0 0 1 1 1
                              1 1 .9338073 3 5 1 52.31217 66.98598 0 0 0 0 0 1 0 1 1 1
                              1 1 .9338073 4 0 0 35.53353 54.33734 0 0 0 0 0 0 0 0 1 1
                              1 1 .9338073 4 1 1 -39.36005 -20.976246 0 1 0 0 0 0 0 1 1 1
                              1 1 .9338073 4 2 1 -9.110801 8.973006 0 0 1 0 0 0 0 1 1 1
                              1 1 .9338073 4 3 1 26.09574 42.86954 0 0 0 1 0 0 0 1 1 1
                              1 1 .9338073 4 4 1 -27.843304 -10.169497 0 0 0 0 1 0 0 1 1 1
                              1 1 .9338073 4 5 1 13.87387 28.547676 0 0 0 0 0 1 0 1 1 1
                              1 1 .9338073 5 0 0 -20.020956 -1.2171488 0 0 0 0 0 0 0 0 1 1
                              1 1 .9338073 5 1 1 4.943902 23.32771 0 1 0 0 0 0 0 1 1 1
                              1 1 .9338073 5 2 1 -24.22479 -6.140981 0 0 1 0 0 0 0 1 1 1
                              1 1 .9338073 5 3 1 -16.969576 -.19576862 0 0 0 1 0 0 0 1 1 1
                              1 1 .9338073 5 4 1 -24.115284 -6.441477 0 0 0 0 1 0 0 1 1 1
                              1 1 .9338073 5 5 1 30.288513 44.96232 0 0 0 0 0 1 0 1 1 1
                              2 2 -.25856757 1 0 0 27.09463 44.70606 0 0 0 0 0 0 0 0 1 2
                              2 2 -.25856757 1 1 0 27.93563 40.12706 0 1 0 0 0 0 0 0 1 2
                              2 2 -.25856757 1 2 1 96.68483 113.57626 0 0 1 0 0 0 0 1 1 2
                              2 2 -.25856757 1 3 1 37.513702 53.09513 0 0 0 1 0 0 0 1 1 2
                              2 2 -.25856757 1 4 1 29.415295 45.89673 0 0 0 0 1 0 0 1 1 2
                              2 2 -.25856757 1 5 1 5.621181 19.102613 0 0 0 0 0 1 0 1 1 2
                              2 2 -.25856757 2 0 0 60.73626 78.34769 0 0 0 0 0 0 0 0 1 2
                              2 2 -.25856757 2 1 0 65.71793 77.90936 0 1 0 0 0 0 0 0 1 2
                              2 2 -.25856757 2 2 1 -22.72153 -5.830101 0 0 1 0 0 0 0 1 1 2
                              2 2 -.25856757 2 3 1 -23.285265 -7.703833 0 0 0 1 0 0 0 1 1 2
                              2 2 -.25856757 2 4 1 70.13183 86.61326 0 0 0 0 1 0 0 1 1 2
                              2 2 -.25856757 2 5 1 39.86688 53.34831 0 0 0 0 0 1 0 1 1 2
                              2 2 -.25856757 3 0 0 -25.54773 -7.936295 0 0 0 0 0 0 0 0 1 2
                              2 2 -.25856757 3 1 0 -7.957322 4.2341104 0 1 0 0 0 0 0 0 1 2
                              2 2 -.25856757 3 2 1 35.971916 52.86335 0 0 1 0 0 0 0 1 1 2
                              2 2 -.25856757 3 3 1 -22.028456 -6.447023 0 0 0 1 0 0 0 1 1 2
                              2 2 -.25856757 3 4 1 8.514469 24.9959 0 0 0 0 1 0 0 1 1 2
                              2 2 -.25856757 3 5 1 13.084335 26.56577 0 0 0 0 0 1 0 1 1 2
                              2 2 -.25856757 4 0 0 48.07889 65.69032 0 0 0 0 0 0 0 0 1 2
                              2 2 -.25856757 4 1 0 4.2618093 16.453241 0 1 0 0 0 0 0 0 1 2
                              2 2 -.25856757 4 2 1 20.635763 37.527195 0 0 1 0 0 0 0 1 1 2
                              2 2 -.25856757 4 3 1 -50.92491 -35.34348 0 0 0 1 0 0 0 1 1 2
                              2 2 -.25856757 4 4 1 40.93797 57.41941 0 0 0 0 1 0 0 1 1 2
                              2 2 -.25856757 4 5 1 -24.621527 -11.140095 0 0 0 0 0 1 0 1 1 2
                              2 2 -.25856757 5 0 0 -14.595343 3.01609 0 0 0 0 0 0 0 0 1 2
                              2 2 -.25856757 5 1 0 -58.15121 -45.95978 0 1 0 0 0 0 0 0 1 2
                              2 2 -.25856757 5 2 1 -30.041 -13.149566 0 0 1 0 0 0 0 1 1 2
                              2 2 -.25856757 5 3 1 -43.92861 -28.347176 0 0 0 1 0 0 0 1 1 2
                              2 2 -.25856757 5 4 1 65.15345 81.63488 0 0 0 0 1 0 0 1 1 2
                              2 2 -.25856757 5 5 1 -31.929667 -18.448235 0 0 0 0 0 1 0 1 1 2
                              3 3 -17.732271 1 0 0 1.8434157 1.9811445 0 0 0 0 0 0 0 0 1 3
                              3 3 -17.732271 1 1 0 -28.53569 -33.817963 0 1 0 0 0 0 0 0 1 3
                              3 3 -17.732271 1 2 0 22.933073 17.350801 0 0 1 0 0 0 0 0 1 3
                              3 3 -17.732271 1 3 1 18.823576 16.931305 0 0 0 1 0 0 0 1 1 3
                              3 3 -17.732271 1 4 1 -3.292431 -4.284703 0 0 0 0 1 0 0 1 1 3
                              3 3 -17.732271 1 5 1 -13.41548 -17.407751 0 0 0 0 0 1 0 1 1 3
                              3 3 -17.732271 2 0 0 .546951 .6846798 0 0 0 0 0 0 0 0 1 3
                              3 3 -17.732271 2 1 0 32.56882 27.28655 0 1 0 0 0 0 0 0 1 3
                              3 3 -17.732271 2 2 0 56.31581 50.73354 0 0 1 0 0 0 0 0 1 3
                              3 3 -17.732271 2 3 1 3.9907484 2.0984771 0 0 0 1 0 0 0 1 1 3
                              3 3 -17.732271 2 4 1 27.64645 26.65418 0 0 0 0 1 0 0 1 1 3
                              3 3 -17.732271 2 5 1 -32.4036 -36.39587 0 0 0 0 0 1 0 1 1 3
                              3 3 -17.732271 3 0 0 14.00032 14.13805 0 0 0 0 0 0 0 0 1 3
                              3 3 -17.732271 3 1 0 47.16051 41.87824 0 1 0 0 0 0 0 0 1 3
                              3 3 -17.732271 3 2 0 -72.6644 -78.24667 0 0 1 0 0 0 0 0 1 3
                              3 3 -17.732271 3 3 1 -5.49064 -7.382911 0 0 0 1 0 0 0 1 1 3
                              3 3 -17.732271 3 4 1 -52.20465 -53.19692 0 0 0 0 1 0 0 1 1 3
                              3 3 -17.732271 3 5 1 -5.030986 -9.023257 0 0 0 0 0 1 0 1 1 3
                              3 3 -17.732271 4 0 0 -14.12911 -13.991382 0 0 0 0 0 0 0 0 1 3
                              3 3 -17.732271 4 1 0 -26.876307 -32.158577 0 1 0 0 0 0 0 0 1 3
                              3 3 -17.732271 4 2 0 -59.76569 -65.34795 0 0 1 0 0 0 0 0 1 3
                              3 3 -17.732271 4 3 1 50.36446 48.47218 0 0 0 1 0 0 0 1 1 3
                              3 3 -17.732271 4 4 1 27.296 26.303726 0 0 0 0 1 0 0 1 1 3
                              3 3 -17.732271 4 5 1 -15.74834 -19.74061 0 0 0 0 0 1 0 1 1 3
                              3 3 -17.732271 5 0 0 29.86576 30.00349 0 0 0 0 0 0 0 0 1 3
                              3 3 -17.732271 5 1 0 10.744653 5.462381 0 1 0 0 0 0 0 0 1 3
                              3 3 -17.732271 5 2 0 23.961567 18.379295 0 0 1 0 0 0 0 0 1 3
                              3 3 -17.732271 5 3 1 24.03723 22.14496 0 0 0 1 0 0 0 1 1 3
                              3 3 -17.732271 5 4 1 21.263737 20.271465 0 0 0 0 1 0 0 1 1 3
                              3 3 -17.732271 5 5 1 8.518919 4.5266476 0 0 0 0 0 1 0 1 1 3
                              end
                              [/CODE]

                              However, as soon as I run xtgeebcv, I get the error: matrix operators that return matrices not allowed in this context r(509);

                              Code:
                              xtgeebcv y i.intrv i.time, cluster(cluster) family(gaussian) link(identity) corr(exchangeable) stderr(kc)
                              If, instead, I run xtgee which is essentially the same command except that it does not allow for the stderr() option after I xtset the data then there are no issues and my code does not break.

                              Code:
                              xtset cluster
                              xtgee y i.intrv i.time, family(gaussian) link(identity) corr(exchangeable)
                              William, I ran the exact same code on the sample data (mkvtrial.dta) that is provided in the package and get the same error.

                              Code:
                              xtgeebcv know i.arm i.stratum i.ethnicgp, family(binomial) link(logit) cluster(community) stderr(kc)
                              Code:
                              Note: Family is binomial and link is logit
                              Using exchangeable working correlation
                              with scale parameter divided by K - p
                                     panel variable:  community (unbalanced)
                              
                              Iteration 1: tolerance = .12510611
                              Iteration 2: tolerance = .00682197
                              Iteration 3: tolerance = .00041936
                              Iteration 4: tolerance = .00002545
                              Iteration 5: tolerance = 1.548e-06
                              Iteration 6: tolerance = 9.416e-08
                              
                              GEE population-averaged model                   Number of obs     =      4,100
                              Group variable:                  community      Number of groups  =         20
                              Link:                                logit      Obs per group:
                              Family:                           binomial                    min =        169
                              Correlation:                  exchangeable                    avg =      205.0
                                                                                            max =        257
                                                                              Wald chi2(4)      =      43.75
                              Scale parameter:                         1      Prob > chi2       =     0.0000
                              
                              ------------------------------------------------------------------------------
                                      know |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                              -------------+----------------------------------------------------------------
                                     1.arm |   .8270697   .1482322     5.58   0.000     .5365398    1.117599
                                           |
                                   stratum |
                                        2  |   .0503953    .179305     0.28   0.779    -.3010361    .4018266
                                        3  |   .1252695   .1924411     0.65   0.515    -.2519082    .5024471
                                           |
                                1.ethnicgp |  -.3040093   .0879244    -3.46   0.001    -.4763379   -.1316807
                                     _cons |  -.0108448    .164238    -0.07   0.947    -.3327454    .3110558
                              ------------------------------------------------------------------------------
                              matrix operators that return matrices not allowed in this context
                              r(509);
                              Is this the reason for the error something to do with the command itself?
                              Last edited by CEdward; 03 Aug 2020, 22:02.

                              Comment

                              Working...
                              X