Announcement

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

  • Feeding values through loop in power calculation

    Hi all,
    I'm trying to write this loop where I want to feed the arguments of the "power" function by taking values of the control mean, SD, difference, and control and treatment group sizes from each row. Then I want to store the resulting r(power) value against the same row (in the corresponding rows of Power1 variable). Specifically, I used the following
    HTML Code:
    [CODE]
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int days float(Cmean Cstddev Ccount Tcount Cstddevnew Power1)
      0         0         0   0   6         0 .
      1         0         0   0   6         0 .
      2         0         0   2   6         0 .
      3         0         0   2  10         0 .
      4 .16666667  .4082483   6  10 .13608277 .
      5 .16666667  .4082483   6  11 .13608277 .
      6 .14285715  .3779645   7  13 .12598816 .
      7 .14285715  .3779645   7  13 .12598816 .
      8      .125  .3535534   8  13 .11785113 .
      9        .2   .421637  10  16 .14054568 .
     10 .16666667  .3892495  12  26 .12974982 .
     11 .16666667  .3892495  12  26 .12974982 .
     12 .16666667  .3892495  12  27 .12974982 .
     13 .16666667  .3892495  12  33 .12974982 .
     14 .16666667  .3892495  12  34 .12974982 .
     15 .14285715  .3631365  14  34  .1210455 .
     16 .14285715  .3631365  14  44  .1210455 .
     17  .1923077  .4019185  26  46 .13397282 .
     18  .2535211  .4381229  71  46 .14604098 .
     19 .24324325  .4319694  74  59  .1439898 .
     20 .25333333   .437849  75  75 .14594965 .
     21 .28431374  .4533145 102  81 .15110485 .
     22  .2882883  .4550202 111  82  .1516734 .
     23   .302521  .4612919 119  87 .15376396 .
     24   .296875  .4586762 128  93 .15289207 .
     25  .3191489  .4678087 141 104 .15593623 .
     26  .3333333  .4730499 144 110  .1576833 .
     27  .3310345  .4722166 145 111 .15740553 .
     28  .3287671  .4713823 146 127 .15712743 .
     29  .3265306  .4705471 147 127 .15684904 .
     30   .316129  .4664711 155 144  .1554904 .
     31  .3227848  .4690278 158 170  .1563426 .
     32  .3209876  .4683037 162 182 .15610123 .
     33  .3227513  .4687703 189 199 .15625677 .
     34  .3210526  .4681145 190 212 .15603815 .
     35  .3112245 .46418005 196 232  .1547267 .
     36   .315534  .4658603 206 255 .15528676 .
     37  .3348837  .4730512 215 273 .15768373 .
     38  .3409091  .4750958 220 278  .1583653 .
     39      .348 .47729155 250 288  .1590972 .
     40  .3505976  .4781105 251 297 .15937017 .
     41  .3478261  .4772246 253 302 .15907486 .
     42  .3464567  .4767803 254 304 .15892676 .
     43  .3490196  .4775976 255 304  .1591992 .
     44   .351145  .4782417 262 313  .1594139 .
     45   .351145  .4782417 262 330  .1594139 .
     46 .34586465   .476546 266 346 .15884866 .
     47 .34586465   .476546 266 358 .15884866 .
     48 .34586465   .476546 266 374 .15884866 .
     49   .349481  .4776331 289 380 .15921104 .
     50  .3503401  .4778899 294 383  .1592966 .
     51  .3503401  .4778899 294 409  .1592966 .
     52  .3525424  .4785735 295 432  .1595245 .
     53  .3642384  .4820147 302 438 .16067155 .
     54  .3630363  .4816707 303 441  .1605569 .
     55  .3630363  .4816707 303 444  .1605569 .
     56  .3630363  .4816707 303 444  .1605569 .
     57  .3651316  .4822609 304 444 .16075362 .
     58  .3672131  .4828375 305 444  .1609458 .
     59  .3672131  .4828375 305 447  .1609458 .
     60  .3672131  .4828375 305 452  .1609458 .
     61  .3672131  .4828375 305 465  .1609458 .
     62  .3672131  .4828375 305 467  .1609458 .
     63  .3680782  .4830701 307 475  .1610234 .
     64  .3680782  .4830701 307 477  .1610234 .
     65  .3680782  .4830701 307 477  .1610234 .
     66  .3680782  .4830701 307 495  .1610234 .
     67  .3680782  .4830701 307 510  .1610234 .
     68  .3680782  .4830701 307 512  .1610234 .
     69  .3680782  .4830701 307 512  .1610234 .
     70  .3680782  .4830701 307 512  .1610234 .
     71  .3680782  .4830701 307 532  .1610234 .
     72  .3680782  .4830701 307 532  .1610234 .
     73  .3680782  .4830701 307 532  .1610234 .
     74  .3680782  .4830701 307 540  .1610234 .
     75  .3680782  .4830701 307 540  .1610234 .
     76  .3680782  .4830701 307 540  .1610234 .
     77  .3680782  .4830701 307 548  .1610234 .
     78  .3680782  .4830701 307 553  .1610234 .
     79  .3680782  .4830701 307 553  .1610234 .
     80  .3680782  .4830701 307 554  .1610234 .
     81  .3680782  .4830701 307 554  .1610234 .
     82  .3680782  .4830701 307 554  .1610234 .
     83  .3680782  .4830701 307 554  .1610234 .
     84  .3680782  .4830701 307 554  .1610234 .
     85  .3680782  .4830701 307 557  .1610234 .
     86  .3680782  .4830701 307 563  .1610234 .
     87  .3680782  .4830701 307 566  .1610234 .
     88  .3680782  .4830701 307 568  .1610234 .
     89  .3680782  .4830701 307 573  .1610234 .
     90  .3680782  .4830701 307 573  .1610234 .
     91  .3680782  .4830701 307 573  .1610234 .
     92  .3680782  .4830701 307 584  .1610234 .
     93  .3680782  .4830701 307 589  .1610234 .
     94  .3680782  .4830701 307 589  .1610234 .
     95  .3680782  .4830701 307 589  .1610234 .
     96  .3680782  .4830701 307 589  .1610234 .
     97  .3680782  .4830701 307 589  .1610234 .
     98  .3680782  .4830701 307 589  .1610234 .
     99  .3680782  .4830701 307 589  .1610234 .
    100  .3680782  .4830701 307 589  .1610234 .
    101  .3680782  .4830701 307 589  .1610234 .
    102  .3680782  .4830701 307 589  .1610234 .
    103  .3680782  .4830701 307 589  .1610234 .
    104  .3680782  .4830701 307 589  .1610234 .
    105  .3680782  .4830701 307 589  .1610234 .
    106  .3680782  .4830701 307 589  .1610234 .
    107  .3680782  .4830701 307 589  .1610234 .
    108  .3680782  .4830701 307 589  .1610234 .
    109  .3680782  .4830701 307 589  .1610234 .
    110  .3680782  .4830701 307 589  .1610234 .
    111  .3680782  .4830701 307 589  .1610234 .
    112  .3721683   .484167 309 589   .161389 .
    end
    [/CODE]
    The code I used is
    HTML Code:
    [CODE]
    forval i = i = 5/113 {
    power twomeans Cmean[`i'], sd(Cstddev[`i']) diff(Cstddevnew[`i']) n1(Ccount[`i']) n2(Tcount[`i'])
    
    replace Power1= r(power) in `i'
    }
    [/CODE]
    I'm unable to execute even the first part of actual calculation; the error I get says -
    option n1() must contain positive integers
    r(121);

    I'm feeling a bit clueless on how to solve this. Any help will be appreciated. Thanks!

  • #2

    Code:
     power twomeans Cmean[`i'], sd(Cstddev[`i']) diff(Cstddevnew[`i']) n1(Ccount[`i']) n2(Tcount[`i'])
    is going to disappoint, as Stata won't evaluate on the fly unless asked to. You need

    Code:
    power twomeans `=Cmean[`i']'
    and so on putting

    Code:
    `=   '
    around each reference.

    Comment


    • #3
      Thank you so much, it works now!

      Comment

      Working...
      X