Announcement

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

  • Collect regression output after running loop

    Hello everyone,

    After struggling over this problem for a bit I've decided to break and ask for help. I can't for the life of me see where the problem is so I'm hoping someone else can put me out of my misery.

    In brief, I'm running a series of regressions in a loop and I want to use collect to put them into a succinct table. As you will see in the code, there are a variety of outcomes with the same independent variable in each of the regressions.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(frozen round n_oocytes d3embryos d5embryos embryotransfer dayofET hcg pregnancy miscarriage livebirth)
    1 0  4 2 2 0 5 0 0 0 0
    0 0  0 0 0 . . . . . .
    0 0  0 0 0 . . . . . .
    0 0  7 6 6 0 5 1 1 0 1
    1 0  2 0 0 . . . . . .
    0 0  1 0 0 . . . . . .
    1 0  1 1 0 0 3 1 0 0 0
    1 0  5 1 0 . . . . . .
    1 0  3 3 0 . . . . . .
    1 0  0 0 0 . . . . . .
    1 0  0 0 0 . . . . . .
    1 0  1 1 0 0 3 0 0 0 0
    0 0  1 0 0 . . . . . .
    1 0  8 2 1 0 5 1 1 1 0
    1 0  0 0 0 . . . . . .
    1 0  2 1 1 0 3 0 0 0 0
    0 0  9 5 3 . . . . . .
    1 0  2 0 0 . . . . . .
    1 0  2 1 1 0 5 0 0 0 0
    1 0  5 3 3 0 5 0 0 0 0
    1 0  2 1 1 0 5 0 0 0 0
    1 0  2 0 0 . . . . . .
    1 0  5 2 2 0 5 1 0 0 0
    1 0  8 2 3 0 5 0 0 0 0
    1 0  8 2 3 1 5 0 0 0 0
    0 0 13 7 2 0 5 0 0 0 0
    1 0  6 3 0 0 3 0 0 0 0
    1 0  0 0 0 . . . . . .
    1 0  2 1 0 0 3 0 0 0 0
    1 0  2 1 0 . . . . . .
    1 0  2 1 0 . . . . . .
    0 0  0 0 0 . . . . . .
    1 0  1 1 0 0 3 0 0 0 0
    1 0  7 2 0 0 3 0 0 0 0
    1 0  1 0 0 . . . . . .
    0 0  0 0 0 . . . . . .
    1 0  0 0 0 . . . . . .
    0 0  4 1 0 . . . . . .
    1 0  1 0 0 . . . . . .
    1 0  2 1 0 . . . . . .
    1 0  5 3 3 0 5 0 0 0 0
    0 0  4 2 0 0 3 0 0 0 0
    1 0  0 0 0 . . . . . .
    1 0  5 4 2 0 5 0 0 0 0
    1 0  1 1 0 . . . . . .
    1 0  5 3 0 . . . . . .
    1 0  7 2 0 0 3 0 0 0 0
    1 0 10 2 1 0 5 0 0 0 0
    1 0  2 2 1 0 5 0 0 0 0
    1 0  3 1 0 . . . . . .
    1 0  0 0 0 . . . . . .
    0 0  3 2 2 0 5 0 0 0 0
    1 0  4 2 0 . . . . . .
    1 0  1 0 0 . . . . . .
    0 0  0 0 0 . . . . . .
    0 0  2 1 1 0 5 0 0 0 0
    1 0  3 1 0 . . . . . .
    1 0  2 1 0 . . . . . .
    1 0  2 2 0 0 3 0 0 0 0
    0 0  5 2 0 . . . . . .
    0 0  2 0 0 . . . . . .
    1 0  4 2 1 0 5 0 0 0 0
    1 0  7 0 0 . . . . . .
    1 0  5 3 1 0 5 0 0 0 0
    1 0  3 1 1 1 5 0 0 0 0
    0 0  1 1 0 . . . . . .
    1 0  6 6 2 0 5 0 0 0 0
    1 0  4 3 2 1 5 0 0 0 0
    1 0  4 3 2 1 5 0 0 0 0
    1 0  1 0 0 . . . . . .
    1 0  0 0 0 . . . . . .
    0 0  2 0 0 . . . . . .
    1 0  2 1 1 0 5 0 0 0 0
    1 0  1 0 0 . . . . . .
    1 0  2 2 0 0 3 0 0 0 0
    1 0  5 5 0 0 3 0 0 0 0
    1 0  4 1 0 0 3 0 0 0 0
    0 0  4 0 0 . . . . . .
    1 0  1 1 0 0 3 0 0 0 0
    1 0  2 0 0 . . . . . .
    1 0  0 . . . . . . . .
    1 0  2 2 0 . . . . . .
    0 0  3 0 0 . . . . . .
    1 0  1 0 0 . . . . . .
    0 0  1 1 1 0 5 0 0 0 0
    1 0  2 0 0 . . . . . .
    1 0  9 6 2 0 5 0 0 0 0
    1 0  9 6 2 1 5 0 0 0 0
    1 0  3 3 1 0 5 0 0 0 0
    1 0  4 0 0 . . . . . .
    1 0  0 0 0 . . . . . .
    1 0  0 0 0 . . . . . .
    1 0  0 0 0 . . . . . .
    0 0  2 1 0 . . . . . .
    1 0  3 3 0 1 5 1 1 0 1
    1 0  1 0 0 . . . . . .
    1 0  1 0 0 . . . . . .
    1 0  0 0 0 . . . . . .
    1 0  0 0 0 . . . . . .
    1 0  0 0 0 . . . . . .
    end
    label values frozen frozen
    label values embryotransfer frozen
    label def frozen 0 "fresh", modify
    label def frozen 1 "frozen", modify
    label values round round
    label def round 0 "elongated", modify
    label var frozen "fresh vs. frozen spermatids" 
    label var round "elongated vs. round spermatids" 
    label var n_oocytes "number of oocytes fertilized" 
    label var d3embryos "number of d3 embryos" 
    label var d5embryos "number of d5 embryos" 
    label var embryotransfer "fresh vs. frozen embryo transfer" 
    label var dayofET "Day of embryo transfer" 
    label var hcg "Positive hCG" 
    label var pregnancy "Clinical Pregnancy" 
    label var miscarriage "Miscarriage" 
    label var livebirth "Live Birth"

    Code:
    collect clear
    foreach var of varlist  n_oocytes d3embryos d5embryos embryotransfer dayofET hcg pregnancy miscarriage livebirth {
         qui collect _r_b _r_ci _r_p, tag(model[`var']): regress `var' frozen
    }
    
        collect style cell, nformat(%5.2f)
        collect style cell result[_r_ci], sformat("(%s)")
        collect style cell result[_r_ci], cidelimiter(-)
        collect style cell result, halign(center)
        collect title "Fresh vs. Frozen spermatids"
        collect layout (colname) (result[_r_b _r_ci _r_p])
    I keep getting the error message
    Your layout specification does not uniquely match any items. One or more of the following
    dimensions might help uniquely match items: cmdset, coleq, model.
    I have done this before with success but I am stymied as to why it is not working now. Admittedly I use -collect- infrequently so I am hoping someone with more familiarity will help me out. The reason for the complexity is that I want the table arranged horizontally with each model on a separate row (omitting the constant) and the columns being the beta-coefficient, confidence intervals and p-values as columns.

    Thank you to whoever can point what is probably a simple omission on my part.

    Chris

  • #2
    You need to add one of the dimensions in the error message to your layout. In the calls to collect in your loop, you add a custom dimension named model with the name of the outcome variable as the level, so I imagine you want those variable names in row or column headers. You do not need model, when coleq also serves this purpose and picks up the variable labels too.

    Here is a layout that produces a table, where the models are arranged in the rows using dimension coleq.
    Code:
    collect layout (coleq#colname) (result[_r_b _r_ci _r_p])
    Here is the resulting table.
    Code:
    Fresh vs. Frozen spermatids
    --------------------------------------------------------------------
                                     | Coefficient     95% CI    p-value
    ---------------------------------+----------------------------------
    number of oocytes fertilized     |                                  
      fresh vs. frozen spermatids    |    -0.09    (-1.39- 1.22)   0.89 
      Intercept                      |     2.91     (1.76- 4.06)   0.00 
    number of d3 embryos             |                                  
      fresh vs. frozen spermatids    |     0.03    (-0.76- 0.82)   0.94 
      Intercept                      |     1.32     (0.62- 2.01)   0.00 
    number of d5 embryos             |                                  
      fresh vs. frozen spermatids    |    -0.18    (-0.67- 0.32)   0.49 
      Intercept                      |     0.68     (0.24- 1.12)   0.00 
    fresh vs. frozen embryo transfer |                                  
      fresh vs. frozen spermatids    |     0.17    (-0.15- 0.48)   0.29 
      Intercept                      |    -0.00    (-0.29- 0.29)   1.00 
    Day of embryo transfer           |                                  
      fresh vs. frozen spermatids    |    -0.39    (-1.24- 0.46)   0.36 
      Intercept                      |     4.67     (3.88- 5.46)   0.00 
    Positive hCG                     |                                  
      fresh vs. frozen spermatids    |    -0.06    (-0.35- 0.24)   0.71 
      Intercept                      |     0.17    (-0.11- 0.44)   0.22 
    Clinical Pregnancy               |                                  
      fresh vs. frozen spermatids    |    -0.11    (-0.34- 0.12)   0.34 
      Intercept                      |     0.17    (-0.05- 0.38)   0.13 
    Miscarriage                      |                                  
      fresh vs. frozen spermatids    |     0.03    (-0.11- 0.17)   0.69 
      Intercept                      |    -0.00    (-0.13- 0.13)   1.00 
    Live Birth                       |                                  
      fresh vs. frozen spermatids    |    -0.14    (-0.33- 0.05)   0.15 
      Intercept                      |     0.17    (-0.01- 0.34)   0.06 
    --------------------------------------------------------------------

    Comment


    • #3
      That does it. Thank you Jeff. I'm still a little unclear as to why you need to specify both colname and coleq for the rows (especially since in a prior project I didn't and it worked fine, although now I cannot find that work to prove my point). I suspect that reflects my not having fully internalized how -collect- works. If you could clarify the point, I would be greatly appreciative.

      Comment


      • #4
        If your collection contains a single results set, or colname
        somehow uniqely identifies across mutliple resutls sets (not very
        likely), then you would not need coleq in the layout.

        In your example, there are 9 sets of regression results that are
        collected. So there are 9 intercepts and 9 slopes identified by the
        levels of colname in your row specification and
        result[_r_b] in your column specification. collect layout
        will only populate a table's cell if its row-column specification
        identifies a single item in the collection, so must tell collect
        how to arrange these 9 items with cmdset or eqname.

        The levels of cmdset index the results collected, 1 for the first
        set, 2 for the second set, ...

        For regress estimation results, collect puts the dependent
        variable as the level of eqname for each model coefficient.

        Comment


        • #5
          Thanks Jeff. Okay, I think I'm starting to wrap my head around this.

          So why would this example below work? What's qualitatively different about this example where I don't need to specify anything after colname? Is it because the dependent variable in this equation is the same across the loop and the model names are set by the independent variable? I'm still struggling a bit to get this straight in my head.

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float BeckAScoreMax double(PWVwk10 PWVwk14 PWVwk18 PWVwk22 PWVwk26 PWVwk30 PWVwk34 PWVwk38) float T1Rwk10 double(T1Rwk14 T1Rwk18 T1Rwk22 T1Rwk26 T1Rwk30 T1Rwk34) float T1Rwk38
           3         7.2           6           .         9.5         7.3           .           .       7.134 125.66666 127.6666667           .       129.5           .       139.5           . 131.01067
          10           . 8.229333333           .       7.442 7.444666667 7.814666667           .           . 140.33333 141.6546667         150 146.1466667      133.49 134.6066667           .         .
           2       6.296        6.45           .           .        6.55        6.85        7.15           . 152.23666         163           .           .           . 150.6666667         150         .
           3         4.7         6.7         5.9        5.95           .           .           .        5.75 160.66667           .           .       155.5       165.5       163.5      151.25   147.872
           3         7.9           .         5.8         6.1         8.1        8.05         8.3 6.618666667     149.5         153       148.5         149           .       166.5           .       148
           6        7.05         7.3         6.5        7.35           .         8.7         9.9           .       134       144.5       144.5         140           .           .         130         .
           2         6.8        5.35        6.65           .        6.85        5.95        8.85           . 146.66667         197       159.5           .         153           . 151.1666667         .
          16         6.8         6.9         7.7       6.214        6.15           .         7.1           . 134.66667       134.5         143 146.2166667       142.5           .         147         .
           9        6.75         5.9 5.639666667         6.6           .           .        6.75         6.2       148         151 153.1006667 151.8841905 149.9453333      149.56           .         .
          10        7.95           .           .           .         6.6           .           .           .         .         164           .       157.5           .           .         154         .
           8          20         5.2        6.65        5.25         5.7         5.5         4.6           . 136.66667       139.5       129.5       131.5           .         132           .         .
           4           .         5.3         5.7           .         7.5           .        5.45         5.6 139.33333 148.3333333         153         150       147.5           .         145     144.5
           2         6.2         6.3           .           .           .        6.95        5.25           . 139.33333 148.3333333         153         150       147.5           .         145     144.5
          11           . 6.543333333         6.7           .           .         5.6        6.75        6.55       140 142.7453333         145           .           . 137.3333333       145.5     147.5
           2         5.4        5.55        5.75 5.166666667        5.35 5.766666667        6.25           .     147.5         144         152         144       138.5         145 153.6666667     144.5
           1        7.15         6.4           .        5.45        5.55        7.45       6.475           .         .      146.75           .       157.5         154         158         152         .
           4        6.55         6.9           .         6.2         5.9        6.35           .         8.1       159       146.5           .       160.5       159.5         148           .       140
           5         6.3           .           .         7.3         7.4        7.05        8.25           .       149           .           .         154       142.5         152           .       142
           3           . 7.502666667         6.8       6.842           . 7.056666667           .           . 134.66667 142.4253333           . 142.4266667           . 135.9973333         140 146.66667
           1           . 5.966666667         6.5           . 5.833333333           .       6.387        6.15         . 154.9853333 156.6666667         162         157           . 151.3816667     145.6
          14         8.4        7.05        7.85         7.6       6.975           .           .       10.35     138.5         180           .           .         145 157.3333333       154.5       150
          17           5           .         5.4        5.55        6.05         5.1        5.65           .       160           .       161.5         159         154         156       151.4         .
           5         6.8        5.25           .           .        5.85         5.2         5.6         6.5     138.5         180           .           .         145 157.3333333       154.5       150
           7       6.564         6.2           .         6.3         5.7        6.05         6.8       6.904   143.222      147.25           .         145         146 139.3333333       142.5   143.928
           4        6.35         6.1        5.15         7.2           .           .           .           .       147         147         155       145.5           .           .           .         .
           5       6.504        5.65         6.2         7.8         6.6 5.433333333           .         7.2 140.60333         146         146       141.5 149.6666667       153.5 146.3333333         .
          10       6.309         7.5         5.3           .           .        6.25           .         7.4    147.86       162.5       166.5           .           .       150.5         150     170.5
           7           7           .         5.3         5.8         5.1         5.7           .           .       148           .         149         151         150         147           .         .
           9 5.538333333        4.25           .         4.9           .           .           .           .   146.032         144           .       140.5           .         137         150         .
           6       5.975         5.4         5.2 4.866666667        7.05           .        5.95           .       146 147.3333333         156         153         147           . 153.6666667         .
           0           .           . 5.166666667        4.65 4.866666667           .           5           .         .           . 151.6533333         145         146       154.5      142.25         .
           5         7.2         6.6        6.85           .        7.15        6.75         6.6           .     141.5         158      145.75           .         155         156       143.5         .
          15       6.987         6.7           .           .         5.7           .           .           .    146.71       142.5         152           .       137.5           .           .     138.2
          11         6.7         7.6        6.85           .           .           .        7.25           .     148.5 148.3333333         146           .           .      140.25         159         .
           7         7.1 6.376666667 6.566666667         6.2         8.5        7.55 7.087666667           .     154.5     151.132         159 154.6666667       140.5 139.6666667 149.6693333         .
          12         5.7           .         6.1         5.2        5.85        5.05        5.45           .         .           .         148         161       139.8 153.6666667           .         .
           2         7.5        6.55           . 6.966666667         5.4         5.7           .        5.85     144.5       144.5           .       150.5       144.5         148           .       140
           4        5.65         5.6         4.4           .           5        5.35        5.55           .       175 178.6666667         173           .      179.75     168.875      146.75         .
           6        6.15           .        5.65        5.35         5.8 6.166666667         5.9 6.629333333       175           .         142       148.5         141       142.6       140.5 138.17067
          15        8.15        6.65           .         8.7        6.55           .        9.05           .     151.5         153           .         157         147           .           .         .
           7         5.7           .           .        6.33           . 6.495333333           .           .         .           .           . 143.4533333           . 142.4514286         133         .
           5         6.7         7.2           .        6.25           .           .           .         7.5 144.83333         152           .         135           .           .       137.5       137
           2 6.295333333         6.8       6.075        5.85         6.1         5.8 6.466666667       6.919    149.41       155.5         159      150.75 151.6666667      149.25         155   154.432
           3       8.076        8.95           .         7.3         9.6        7.05           .       7.187 128.15067       129.5           .       127.5       129.6 115.3333333         125 132.63066
           8         7.1        8.95         8.4       11.05        7.65        8.05           .           . 137.66667         139         138 132.3333333         135       138.5           .         .
           5       5.935         4.9         5.2           .           .         5.3         6.7           . 141.20667         140         141           .           .         144         141         .
           6        5.25         6.7        6.55         7.1           .           .           .           .     138.5         144       145.5         137           .           .           .         .
          13           .           .        5.65           7 5.266666667           6        8.15       7.153       140           .         141 138.6666667 134.3333333       140.5       136.5 145.09067
           5        5.95           .         5.2           .         6.6        5.25         5.8           .       185           .      197.25           .       108.5       185.5 172.8571429     159.8
           9        4.75        5.65        6.65 6.033333333        5.05           .         6.8           .     144.5 143.6666667       151.5 150.6666667         154       151.5 147.3333333       143
           5 6.666666667        5.15           .        6.85           .           .         6.2        6.85       136         143           . 142.6666667           .           .         146       139
           4         5.5        6.55        6.05        7.85         5.2        6.55        9.15           . 133.66667         138 138.3333333           .         144 143.3333333 129.3333333         .
          11        5.25           .         6.1         5.7         5.7        5.95         5.6           .     136.5           .         138       153.5         146 133.6666667         143         .
           3        7.05 5.166666667        5.85           .        6.05        7.45         6.5           . 135.33333 149.6666667       144.5           .           . 145.6666667       144.5         .
           8        4.65        5.95         5.9         7.3        6.36         7.1           .           . 120.33334 135.6666667      140.25         141      138.12         117           .         .
           3         4.9       7.325         6.1           .        6.55         8.1        7.15           . 143.66667       139.5           .           . 150.3333333 150.2857143       149.5         .
           3        7.45         7.1        6.15         7.3 7.133333333 7.666666667           .         6.2     136.5         140 144.6666667       146.5       125.5         142           .     135.5
           0         6.1         5.3         5.7           .        6.75        6.35        6.05        6.35 146.66667 153.6666667 149.6666667           .       146.5         145         146     148.5
          13 5.613333333         5.7        5.85           .        5.15        5.95         5.6        5.45 151.54333 155.6666667       159.5           .         160         160       159.5       149
           2         6.4        7.35        6.45        6.45        7.65        7.75        6.75         7.9 138.33333       141.5       139.5         134       134.5       136.5 130.3333333 125.16666
           5           . 6.259333333           .           .         4.9         6.7           .           .       141 152.1253333         152         144           .       156.2           .         .
           0       7.168           .           .           . 7.433333333         7.9           .           .   149.252       127.5           . 151.3333333         103 137.6666667         149         .
          26 6.457666667        5.75 6.633333333         6.4        5.55           .           .           . 147.34334 149.3333333       161.5       145.5         157           .         148         .
          15         7.2         6.4           .           .           .           .           .           .     138.5       132.5         175           .           .           .         157         .
           3       7.675        7.95           .         5.9        6.35           .        7.05           .    130.75         131         136         140         138           .         124         .
           4        4.65         4.1           .        6.05        4.65        4.55         5.6       6.042 162.66667         164           .         151       175.5       157.6         152   147.724
           0         6.1         6.2           .         6.3        5.95        7.25        6.55         7.3       159         154           . 144.6666667         168         163         160     159.5
           6        6.15        6.95        5.65         5.3        5.55        6.15       7.275           .     141.5 140.3333333       140.5 141.6666667       143.5       140.5      139.75     143.5
          16        6.55         6.5        7.42         7.3         8.1           .           .           .       146         144 154.6093333         154       151.5     156.125           .         .
           6         5.8         5.8           .        4.75         5.1        5.65        6.75           . 162.66667         164           .         151       175.5       157.6         152   147.724
          24         5.2        5.75        5.05       5.598         6.3           .           .           .       159         154           . 144.6666667         168         163         160     159.5
           4         5.6        6.45        5.55        4.95        5.55         4.7        6.85        6.25     141.5 140.3333333       140.5 141.6666667       143.5       140.5      139.75     143.5
           5        5.95           .           .         5.1         5.3         7.4        7.15           .       146         144 154.6093333         154       151.5     156.125           .         .
          13         6.4        5.55 5.676666667         5.5       5.884         5.3           .           . 154.33333       155.5       157.2         157      156.85         157           .         .
           7        6.65         6.2        6.15        5.55           .         5.8 5.666666667           .     148.5         153 145.3333333       141.5       142.5         142       144.5         .
           9       10.05           .         9.1        9.25       10.15           .        11.2           .       128           .         123       128.5       131.5           .           .         .
          12       6.157         6.4         6.9        5.65        5.95        5.65         7.6        7.15     142.3 157.3333333       145.5         151       155.5         155         141       154
           4         6.1         6.5        6.05        5.85        5.15         7.2           .           . 140.41667      141.75 138.3333333         149      143.25         146           .         .
           3         5.6         6.3        6.65        6.85        5.75         6.5         7.4       6.773         .         142         143         154      153.75       159.6         146    141.46
           4        5.75        5.35           .        5.45           .         5.8         5.3           .         .         164           .         168         164         157           .     149.5
           3       6.975         5.2         4.8        6.85         6.7           .         7.1 6.523333333       132       145.4       142.6         136       136.5         143       141.5   140.944
          10         6.3        6.45           9        5.55           .           .           .           .     160.5         164 161.6666667      155.75         151           .           .         .
           6         6.9        4.35 5.109666667           . 5.954666667        6.15           .         5.7       146         165 156.0866667         141 150.7773333           .           .     158.5
          20        6.45 6.933333333         7.4           . 8.133333333           .           .           .       150       149.5         143       141.5           .       119.5       156.5     139.5
           2         4.4         4.8        5.25           .        5.55         6.8         4.7           .     145.5 175.3333333         210           .         148         167       154.5         .
           3         5.2         6.1        6.05       5.838         6.5           .        5.35           .       158           .         155 156.0313333         157           .         149         .
           9        6.55           . 7.133333333        5.85         6.5           .         7.8           .       138           .       152.5 141.6666667         146       134.5       138.4         .
           3        8.55 7.809333333         9.2           .         9.1           . 8.150666667           .     141.5 136.2013333         147       144.5         129       128.5 139.5166667         .
           0 5.915333333         6.1           .         6.7        5.95 4.466666667         5.8 6.186666667 149.57666       155.5         148       144.5       145.5       163.5      143.25 143.68933
           0       6.213        6.05         5.7        6.45           .        6.75         5.6           . 151.19667         155       153.5 156.6666667           . 149.3333333         146         .
           6 6.266666667           .         3.7        4.85        7.05           .         5.9           . 143.33333           .         157       156.5 155.3333333         146       146.5         .
          11         5.8         5.6           .           .        6.05         6.2        9.15           7 134.66667       145.5 142.6666667           .         141       143.2           .       134
           5         6.7        5.75           .        5.95         5.5        6.85         9.5        7.54 141.33333 148.8333333       145.5      146.75 155.3333333 149.3333333           .   142.968
          20        5.55        5.85           . 5.654666667           . 5.796666667           .           .    142.25       139.5           . 154.6533333           . 148.1264286         164         .
          13        6.05         5.6           .         5.3         6.9        6.55         6.8         5.7 142.66667 153.6666667           .       151.5       144.5         140         142     149.5
           5        5.25        5.35        5.65 5.166666667           .        6.25        5.45       6.441 153.33333       159.5         173       153.6         149         143     155.125   151.292
          13        6.15           .           .           .           .        5.55           6           .       148       135.5           .           .       138.5 143.6666667         138         .
           7        7.25           .        7.65           .           .           .           .           .       126 131.3333333         133       150.5         150           . 141.6666667       144
          10           .           .           .        5.65        7.15         5.8 6.442666667           .         .           .           .      138.75         149       138.5 138.8933333         .
           6           . 7.266666667           .           .           .           .        6.95         6.8       149           .           .           .           .         142      150.25       142
          end

          Code:
          collect clear
          foreach var of varlist PWVwk10 - T1Rwk38 {
                          qui collect _r_b _r_ci _r_p, tag(model[`var']): regress BeckAScoreMax `var'
          }
              collect style cell, nformat(%5.2f)
              collect style cell result[_r_ci], sformat("(%s)")
              collect style cell result[_r_ci], cidelimiter(-)
              collect style cell result, halign(center)
              collect title "Beck Anxiety  Score"
              collect layout (colname) (result[_r_b _r_ci _r_p])

          Comment


          • #6
            Your example in #5 is almost a perfect example of the second case I
            mention in #4.

            Notice however, that the intercepts from your regressions do not show up
            in the table resulting from your layout. In order to see them, along
            with each of the slopes from the separate regressions, you would have to
            add cmdset or your model dimension to the layout. Adding
            model to the row specification in the layout would show the
            independent variable twice in the row headers, so here is the table
            showing the intercepts and slopes using dimension cmdset.

            Code:
            . collect layout (cmdset#colname) (result[_r_b _r_ci _r_p])
            
            Collection: default
                  Rows: cmdset#colname
               Columns: result[_r_b _r_ci _r_p]
               Table 1: 48 x 3
            
            Beck Anxiety Score
            ------------------------------------------------
                        | Coefficient     95% CI     p-value
            ------------+-----------------------------------
            1           |                                   
              PWVwk10   |     0.03     (-0.63- 0.70)   0.92 
              Intercept |     6.84     (2.38-11.31)    0.00 
            2           |                                   
              PWVwk14   |     0.16     (-1.16- 1.47)   0.81 
              Intercept |     5.82     (-2.47-14.12)   0.17 
            3           |                                   
              PWVwk18   |     1.13     (-0.16- 2.41)   0.08 
              Intercept |     0.23     (-7.85- 8.30)   0.96 
            4           |                                   
              PWVwk22   |    -0.01     (-1.12- 1.11)   0.99 
              Intercept |     7.19     (0.03-14.34)    0.05 
            5           |                                   
              PWVwk26   |     0.14     (-1.04- 1.31)   0.82 
              Intercept |     6.01     (-1.57-13.59)   0.12 
            6           |                                   
              PWVwk30   |    -1.33     (-2.41--0.25)   0.02 
              Intercept |    14.43     (7.46-21.41)    0.00 
            7           |                                   
              PWVwk34   |     0.54     (-0.26- 1.35)   0.18 
              Intercept |     2.30     (-3.22- 7.82)   0.41 
            8           |                                   
              PWVwk38   |     0.93     (-0.59- 2.44)   0.22 
              Intercept |    -0.72    (-11.05- 9.60)   0.89 
            9           |                                   
              T1Rwk10   |     0.01     (-0.10- 0.12)   0.83 
              Intercept |     5.46    (-10.09-21.01)   0.49 
            10          |                                   
              T1Rwk14   |    -0.02     (-0.11- 0.08)   0.73 
              Intercept |     9.37     (-5.31-24.05)   0.21 
            11          |                                   
              T1Rwk18   |    -0.00     (-0.10- 0.09)   0.96 
              Intercept |     7.40     (-6.64-21.43)   0.30 
            12          |                                   
              T1Rwk22   |     0.04     (-0.11- 0.19)   0.62 
              Intercept |     1.43    (-20.58-23.44)   0.90 
            13          |                                   
              T1Rwk26   |     0.04     (-0.06- 0.14)   0.39 
              Intercept |     0.64    (-13.88-15.15)   0.93 
            14          |                                   
              T1Rwk30   |    -0.05     (-0.14- 0.05)   0.36 
              Intercept |    13.41     (-1.04-27.86)   0.07 
            15          |                                   
              T1Rwk34   |     0.15     (-0.00- 0.30)   0.05 
              Intercept |    -15.08   (-37.32- 7.15)   0.18 
            16          |                                   
              T1Rwk38   |     0.12     (-0.06- 0.31)   0.18 
              Intercept |    -11.78   (-38.38-14.82)   0.38 
            ------------------------------------------------

            Comment


            • #7
              Thanks. There's a remarkable variability to the collect command. At least now I have a better sense of why the output can be so different. It never occurred to me combine dimensions in the rows specifications, although I suppose it should have. Thanks again. I'll be better prepared to muddle though this in the future.

              Comment


              • #8
                Sorry one final question (hopefully).

                Code:
                    collect clear
                foreach var of varlist  n_oocytes d3embryos d5embryos embryotransfer dayofET hcg pregnancy miscarriage livebirth {
                     qui collect _r_b _r_ci _r_p, tag(model[`var']): regress `var' round
                }
                
                    collect style cell, nformat(%5.2f)
                    collect style cell result[_r_ci], sformat("(%s)")
                    collect style cell result[_r_ci], cidelimiter(-)
                    collect style cell result, halign(center)
                    collect title "Fresh vs. Frozen spermatids"
                    collect layout (colname[frozen]#model) (result[_r_b _r_ci _r_p])
                I ultimately, went with the model dimension since the intercepts aren't that important to me and I like the compact formatting. My question though is the following? Is there anyway to display the variable labels rather than the variable name in the table output. Right now, that's being set by the -tag- specification in the loop. But is there someway to specify that the label be displayed?

                Thanks again and sorry for the many follow-ups.

                Comment


                • #9
                  For your example in #8, you can use coleq instead of model
                  in the layout.

                  Dimensions across, coleq, colname, roweq,
                  rowname, and var have a special status with collect.
                  At the time an item (result) is consumed by colect, if that item is
                  tagged with one of these dimensions, and the level looks like a variable in
                  the current dataset, that variable's label is consumed too. This is also true
                  of factor variable value labels.

                  Comment


                  • #10
                    Sorry for the late thank you (I was away at conference) but thank you formally and sincerely.

                    Comment

                    Working...
                    X