Announcement

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

  • Undefined local doesn't produce error


    I wrote the code below for estimating sample size for a cluster randomized stepped wedge design (see https://www.jclinepi.com/article/S08...ecd1348717e510). The purpose of the code is not really important, however; what matters is that I've only just discovered that I've been running it with the local -m- undefined, and it does not give an error.

    Code:
    local base=.20
    local int = .15
    local rho=0.01
    
    local k = 2  // # of steps
    local b=1    // # baseline measurements
    local t=1    // # measurements/step
    
    qui {
        foreach rho in 0 0.001 0.005 0.01 0.05 0.10 {         
          local num = (1+`rho'*(`k'*`t'*`m'+`b'*`m'-1))*3*(1-`rho')
          local den= (1+`rho'*(.5*`k'*`t'*`m'+`b'*`m'-1))*2*`t'*(`k'-1/`k')
          local DE=`num'/`den'
        
          power twoproportions `int' `base', power(.90)
          local n1=round(r(N1)*2/`DE')
          local npersite=floor(`n1'/17)
          noi di `rho'  _col(10) %5.3f `DE' _col(20) `n1'  _col(30) `npersite'
        }
    }
    Moreover, I can't figure out what value of -m- is being used; experimenting, m=0 and m=1 give the closest results.

    What am I missing?

    thanks,
    Jeph

  • #2
    If you run the program but remove all references to `m', you'll find that the same results are returned:

    Code:
    local base=.20
    local int = .15
    local rho=0.01
    
    local k = 2  // # of steps
    local b=1    // # baseline measurements
    local t=1    // # measurements/step
    
    qui {
        foreach rho in 0 0.001 0.005 0.01 0.05 0.10 {         
          local num = (1+`rho'*(`k'*`t'*`m'+`b'*`m'-1))*3*(1-`rho')
          local den= (1+`rho'*(.5*`k'*`t'*`m'+`b'*`m'-1))*2*`t'*(`k'-1/`k')
          local DE=`num'/`den'
        
          power twoproportions `int' `base', power(.90)
          local n1=round(r(N1)*2/`DE')
          local npersite=floor(`n1'/17)
          noi di `rho'  _col(10) %5.3f `DE' _col(20) `n1'  _col(30) `npersite'
        }
    }
    
    0        1.000     2424      142
    .001     0.998     2429      142
    .005     0.990     2448      144
    .01      0.980     2473      145
    .05      0.900     2693      158
    .1       0.800     3030      178
    Code:
    local base=.20
    local int = .15
    local rho=0.01
    
    local k = 2  // # of steps
    local b=1    // # baseline measurements
    local t=1    // # measurements/step
    
    qui {
        foreach rho in 0 0.001 0.005 0.01 0.05 0.10 {         
          local num = (1+`rho'*(`k'*`t'*+`b'*-1))*3*(1-`rho')
          local den= (1+`rho'*(.5*`k'*`t'*+`b'*-1))*2*`t'*(`k'-1/`k')
          local DE=`num'/`den'
        
          power twoproportions `int' `base', power(.90)
          local n1=round(r(N1)*2/`DE')
          local npersite=floor(`n1'/17)
          noi di `rho'  _col(10) %5.3f `DE' _col(20) `n1'  _col(30) `npersite'
        }
    }
    
    0        1.000     2424      142
    .001     0.998     2429      142
    .005     0.990     2448      144
    .01      0.980     2473      145
    .05      0.900     2693      158
    .1       0.800     3030      178
    When you don't define a local, Stata substitutes a reference to it with nothing. So for instance `k'*`t'*`m'+`b'*`m'-1 is just `k'*`t'*`b'*-1.

    If you had had something like `k'*`t'*`m'*`b'*`m'-1, Stata would have returned an error because `k'*`t'**`b'*-1 is an invalid expression.

    Comment


    • #3
      Aha. The key is that x-1 and x*-1 both make sense, though they mean very different things.

      I tried 'solving' for a value of m that produced the answer I was getting, but the solution to a*x-1 = a*(-1) is x = 1/a - 1, which varies with the other parameters.

      That's suitably humbling for one day.

      thanks,
      J






      Comment

      Working...
      X