Announcement

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

  • Combining collections of results

    I am trying to combine different results in different collections into one but am unable to figure out how to go about it. Perhaps I'm going about it wrongly. I want the combined results to look like the sample below. I would like to be able to use collect export to export to excel at the end. Kindly help. Thank you.


    Click image for larger version

Name:	ATT Sample Output.jpg
Views:	1
Size:	46.5 KB
ID:	1775332

    Below is my data and my code so far.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float q408a_binary byte(exposure period q104cat) float(wealth_quintile iptw_stabilized) str4 clustercode
    1 1 1 2 1         . "2128"
    1 1 1 2 3  .6334819 "2128"
    1 1 1 1 2  .8872965 "2128"
    1 1 1 2 1   1.63046 "2128"
    1 1 1 2 1         . "2128"
    1 1 1 2 2 1.2247086 "2128"
    1 1 1 2 1         . "2128"
    1 1 1 1 2  1.012563 "2128"
    1 1 1 1 3  .6614283 "2128"
    1 1 1 1 2 1.0122956 "2128"
    1 1 1 2 2 1.2247086 "2128"
    1 1 1 1 1 1.8715497 "2128"
    0 1 1 2 3  .6759744 "2129"
    1 1 1 2 2 1.0476002 "2129"
    1 1 1 1 1 1.1034142 "2129"
    1 1 1 2 2 1.0593003 "2129"
    1 1 1 1 2  .8957604 "2129"
    1 1 1 2 1         . "2129"
    1 1 1 2 3         . "2129"
    1 1 1 1 2  .8955543 "2129"
    1 1 1 2 4  .5979365 "2129"
    1 1 1 1 3  .5950213 "2129"
    1 1 1 2 2 1.0593003 "2129"
    1 1 1 2 1  1.606752 "2129"
    1 1 1 2 2  .9227699 "2130"
    1 1 1 1 1 1.2819333 "2130"
    1 1 1 1 1 1.2990835 "2130"
    1 1 1 2 1  1.606752 "2130"
    1 1 1 1 1 1.2819333 "2130"
    1 1 1 2 2  .9227699 "2130"
    1 1 1 1 1 1.8715497 "2130"
    1 1 1 1 1 1.5357575 "2130"
    1 1 1 2 4  .5745883 "2130"
    1 1 1 1 1 1.5357575 "2130"
    1 1 1 1 2  1.012563 "2130"
    1 1 1 2 2 1.0593003 "2130"
    1 1 1 2 5  .5580806 "2131"
    1 1 1 2 5  .5669054 "2131"
    1 1 1 2 5  .5669054 "2131"
    1 1 1 2 4  .5831169 "2131"
    1 1 1 2 5  .5669054 "2131"
    1 1 1 2 5  .5522093 "2131"
    1 1 1 1 3  .6614283 "2131"
    1 1 1 2 5  .5669054 "2131"
    1 1 1 2 3   .672333 "2131"
    1 1 1 2 5  .5669054 "2131"
    1 1 1 1 5 .54803306 "2131"
    1 1 1 2 5  .5522093 "2131"
    1 1 1 2 3  .6334819 "2133"
    0 1 1 2 3  .7324004 "2133"
    1 1 1 2 5  .5669054 "2133"
    1 1 1 2 4  .5959356 "2133"
    1 1 1 2 3   .672333 "2133"
    1 1 1 1 3         . "2133"
    1 1 1 2 5  .5522093 "2133"
    1 1 1 2 5  .5522093 "2133"
    1 1 1 2 4  .5959356 "2133"
    1 1 1 2 5  .5669054 "2133"
    1 1 1 2 3  .7274547 "2133"
    1 1 1 2 3         . "2133"
    1 1 1 1 5 .54803306 "2134"
    1 1 1 2 5  .5669054 "2134"
    1 1 1 2 2 1.0593003 "2134"
    1 1 1 1 4  .5899439 "2134"
    1 1 1 2 3         . "2134"
    1 1 1 2 2 1.0593003 "2134"
    1 1 1 2 2 1.0476002 "2134"
    1 1 1 2 3         . "2134"
    1 1 1 2 3         . "2134"
    1 1 1 2 4  .5959356 "2134"
    1 1 1 2 5  .5669054 "2134"
    1 1 1 2 5  .5878007 "2134"
    1 1 1 2 5  .5878007 "2135"
    0 1 1 1 5         . "2135"
    1 1 1 2 5  .5580806 "2135"
    1 1 1 2 5  .5669054 "2135"
    1 1 1 2 4         . "2135"
    1 1 1 1 4  .6182836 "2135"
    1 1 1 2 4  .5979365 "2135"
    1 1 1 2 4  .6262231 "2135"
    1 1 1 2 4  .5745883 "2135"
    0 1 1 1 5 .54803306 "2135"
    1 1 1 2 5 .56828284 "2135"
    1 1 1 2 4  .5959356 "2135"
    1 1 1 2 4  .5745883 "2136"
    1 1 1 2 5  .5669054 "2136"
    1 1 1 2 3         . "2136"
    1 1 1 2 5  .5669054 "2136"
    1 1 1 2 4  .5959356 "2136"
    0 1 1 2 5  .5437789 "2136"
    1 1 1 2 5  .5877561 "2136"
    1 1 1 2 5         . "2136"
    1 1 1 2 5         . "2136"
    1 1 1 2 5  .5669054 "2136"
    1 1 1 2 4  .6262231 "2136"
    0 1 1 2 5  .5669054 "2136"
    1 1 1 2 5 .56828284 "2137"
    1 1 1 2 4  .5959356 "2137"
    1 1 1 2 5 .54540646 "2137"
    1 1 1 2 5  .5580806 "2137"
    end
    label values q408a_binary q408a_binary_lbl
    label def q408a_binary_lbl 0 "No", modify
    label def q408a_binary_lbl 1 "Yes", modify
    label values exposure exposure
    label def exposure 1 "Intervention", modify
    label values period period
    label def period 1 "Endline", modify
    label values q104cat q104cat
    label def q104cat 1 "15-17", modify
    label def q104cat 2 "18-19", modify
    label values wealth_quintile wealth_quintile
    label def wealth_quintile 1 "Very poor", modify
    label def wealth_quintile 2 "Poor", modify
    label def wealth_quintile 3 "Averga", modify
    label def wealth_quintile 4 "Rich", modify
    label def wealth_quintile 5 "Very rich", modify

    Code:
    melogit q408a_binary i.exposure##i.period i.q104cat i.wealth_quintile  [pweight=iptw_stabilized] || clustercode:, vce(cluster clustercode) or
    // margins i.exposure#i.period, contrast(nowald) over(wealth_quintile)
    collect clear
    collect create main, replace
    collect stars _r_b 0.05 "*", attach(_r_b) shownote
    quietly collect: margins i.exposure#i.period, contrast(nowald)
    collect style cell result, nformat(%8.3f) 
    collect composite define blu = _r_lb _r_ub, delimiter(,) trim replace
    collect style cell result[blu], sformat("[%s]")
    collect style cell result[_r_b], sformat("%s")
    collect composite define bci = _r_b blu stars, trim replace
    collect style header result, title(hide)
    collect label levels result bci "ATT [95% CI]" 
    collect layout (colname) (result[bci])
    collect save, name(main) replace
    
    
    local cov q104cat wealth_quintile
    foreach v of  local cov {
    collect create `v', replace
    collect stars _r_b 0.05 "*", attach(_r_b) shownote
    quietly collect: margins i.exposure#i.period, contrast(nowald) over(`v')
    collect style cell result, nformat(%8.3f) 
    collect composite define blu = _r_lb _r_ub, delimiter(,) trim replace
    collect style cell result[blu], sformat("[%s]")
    collect style cell result[_r_b], sformat("%s")
    collect composite define bci = _r_b blu stars, trim replace
    collect label levels result bci "ATT [95% CI]" 
    collect style header result, title(hide)
    collect style header `v', title(label)
    collect layout (`v') (result[bci])
    collect save, name(`v') replace
    }

  • #2
    Your code fails when I try to run it because your data extract has no variation in either exposure or period. Please provide an extract with which we can replicate your issue.

    Comment


    • #3
      Originally posted by Hemanshu Kumar View Post
      Your code fails when I try to run it because your data extract has no variation in either exposure or period. Please provide an extract with which we can replicate your issue.
      Here is a more representative sample of the original dataset. Thank you
      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float q408a_binary byte(exposure period q104cat) float(wealth_quintile iptw_stabilized) str4 clustercode
      1 0 1 2 4         . "2266"
      0 0 0 1 1  .7392449 "2220"
      0 0 1 1 1  .8113364 "2222"
      0 1 0 2 5  .6228189 "1104"
      0 0 0 2 2  .8435132 "2217"
      1 1 0 2 4  .6262879 "2105"
      0 1 0 1 2         . "1111"
      0 0 0 1 2         . "2214"
      0 0 1 2 4  .7383448 "4201"
      1 1 1 1 4 .58989817 "2102"
      1 1 1 1 2  1.632937 "1109"
      1 1 1 2 5  .5522093 "2142"
      0 0 1 1 2         . "4217"
      0 0 0 2 4         . "2261"
      0 1 0 2 4  .5959356 "2135"
      1 1 1 2 4         . "2159"
      1 1 1 2 3   .672333 "2119"
      1 0 0 2 1 .51715845 "2231"
      1 1 1 2 4  .5959356 "2109"
      1 1 1 2 4  .5959356 "2134"
      1 1 1 2 3   .672333 "2108"
      0 0 0 1 3  2.073654 "2245"
      0 0 1 1 2         . "2243"
      0 1 0 1 1         . "1122"
      1 1 1 2 3   .672333 "2152"
      1 1 0 1 5 .58229035 "2118"
      1 0 1 1 1 .52606916 "2240"
      1 1 1 2 3  .7274547 "2153"
      0 0 1 1 2         . "2241"
      0 1 0 2 1  1.606752 "2101"
      0 0 1 1 2         . "2265"
      1 1 0 1 5   .562749 "2153"
      0 0 1 1 1  .6798754 "2260"
      1 1 0 1 5  .5627805 "2134"
      1 0 1 2 2  .6567904 "1201"
      1 0 0 2 1         . "2267"
      0 1 0 1 1         . "2132"
      1 0 1 1 5  2.417476 "3216"
      0 1 0 2 4         . "2130"
      0 1 0 2 3  .7274547 "2120"
      1 1 1 2 2 1.2247086 "2139"
      0 0 0 1 4         . "1219"
      1 1 1 2 3         . "1102"
      0 0 0 1 1         . "2221"
      0 0 1 1 3         . "2247"
      1 1 1 2 4  .5959356 "2107"
      0 1 0 2 4  .5959356 "2128"
      1 1 1 2 3  .6334819 "2128"
      1 1 1 2 3   .672333 "2125"
      1 1 0 2 4  .5959356 "2154"
      0 1 0 1 5  .5627805 "2139"
      1 1 1 2 3  .6334819 "2168"
      0 0 0 2 5         . "1205"
      1 1 1 1 4 .58989817 "2101"
      0 1 0 1 4  .6918721 "1112"
      0 1 0 2 4  .6262231 "2164"
      0 0 0 2 5  5.553016 "2228"
      1 1 1 2 3  .6334819 "2154"
      1 1 1 1 5  .5627805 "2114"
      0 1 1 2 3         . "1117"
      0 0 0 2 2  .9464296 "2244"
      0 0 0 2 4         . "2228"
      0 1 0 1 1  1.535216 "2130"
      1 1 0 2 4  .6262231 "2163"
      1 0 0 2 1  .7909834 "2210"
      0 1 0 2 1         . "1120"
      0 1 0 1 3         . "2101"
      0 0 1 2 5  2.293048 "1221"
      0 0 0 2 1 .51758623 "2252"
      0 1 1 2 3  .9904094 "1106"
      1 0 1 2 4 1.4302355 "3216"
      0 0 1 2 1         . "2234"
      1 1 1 2 5  .5669054 "2112"
      0 1 0 2 2 1.0593003 "2135"
      0 1 0 2 3         . "2132"
      1 1 1 2 3  .7275726 "2144"
      0 0 0 2 1 .51758623 "2238"
      0 0 1 1 1         . "4211"
      1 1 1 1 5 .54803306 "2113"
      0 0 0 2 3         . "1221"
      0 0 0 1 1  .7393718 "2203"
      0 0 0 1 1         . "2264"
      1 0 1 1 2         . "1215"
      0 0 0 2 1  .7189214 "2212"
      0 0 0 1 1         . "2202"
      0 0 0 1 3 1.0451207 "1215"
      0 1 0 2 4  .7707077 "1114"
      0 1 0 2 2         . "1120"
      1 0 0 2 2  .5384695 "2226"
      1 1 1 2 5  .5669054 "2117"
      1 1 1 2 2 1.0593003 "2134"
      1 1 1 2 5  .5522093 "2157"
      1 0 0 2 3  .6297176 "2226"
      0 0 1 1 5  .8715369 "2237"
      0 1 0 1 1         . "1113"
      0 0 0 2 2         . "2222"
      1 1 1 2 4  .5959356 "2104"
      1 1 1 2 5  .5580806 "2122"
      0 0 0 2 1         . "2268"
      0 0 1 2 3         . "2226"
      end
      label values q408a_binary q408a_binary_lbl
      label def q408a_binary_lbl 0 "No", modify
      label def q408a_binary_lbl 1 "Yes", modify
      label values exposure exposure
      label def exposure 0 "Control", modify
      label def exposure 1 "Intervention", modify
      label values period period
      label def period 0 "Baseline", modify
      label def period 1 "Endline", modify
      label values q104cat q104cat
      label def q104cat 1 "15-17", modify
      label def q104cat 2 "18-19", modify
      label values wealth_quintile wealth_quintile
      label def wealth_quintile 1 "Very poor", modify
      label def wealth_quintile 2 "Poor", modify
      label def wealth_quintile 3 "Averga", modify
      label def wealth_quintile 4 "Rich", modify
      label def wealth_quintile 5 "Very rich", modify
      Last edited by Kehinde Atoloye; 05 Apr 2025, 03:16.

      Comment


      • #4
        You can add this code at the end of yours:

        Code:
        collect set main
        collect addtags sections[main]
        collect set q104cat
        collect addtags sections[subpop]
        collect set wealth_quintile
        collect addtags sections[subpop]
        
        
        collect combine comb = main q104cat wealth_quintile
        collect layout (sections # (colname[1.exposure#1.period] q104cat wealth_quintile)) (result[bci])
        collect label dim wealth_quintile "Wealth quintile"
        collect label dim q104cat "Age (categories)"
        collect label levels sections main "Main ATT" subpop "Subpopulation ATTs"
        collect title "My title"
        which produces:
        Code:
        . collect preview
        
        My title
        -----------------------------------------------
                                 |         ATT [95% CI]
        -------------------------+---------------------
        Main ATT                 |                     
          Intervention # Endline |  0.609 [0.152,1.067]
        Subpopulation ATTs       |                     
          Age (categories)       |                     
            15-17                |  0.589 [0.090,1.088]
            18-19                |  0.619 [0.164,1.074]
          Wealth quintile        |                     
            Very poor            |  0.678 [0.231,1.124]
            Poor                 | 0.560 [-0.110,1.230]
            Averga               |  0.748 [0.401,1.095]
            Rich                 | 0.495 [-0.069,1.059]
            Very rich            |  0.574 [0.049,1.100]
        -----------------------------------------------
        * p<.05

        Comment


        • #5
          Originally posted by Hemanshu Kumar View Post
          You can add this code at the end of yours:

          Code:
          collect set main
          collect addtags sections[main]
          collect set q104cat
          collect addtags sections[subpop]
          collect set wealth_quintile
          collect addtags sections[subpop]
          
          
          collect combine comb = main q104cat wealth_quintile
          collect layout (sections # (colname[1.exposure#1.period] q104cat wealth_quintile)) (result[bci])
          collect label dim wealth_quintile "Wealth quintile"
          collect label dim q104cat "Age (categories)"
          collect label levels sections main "Main ATT" subpop "Subpopulation ATTs"
          collect title "My title"
          which produces:
          Code:
          . collect preview
          
          My title
          -----------------------------------------------
          | ATT [95% CI]
          -------------------------+---------------------
          Main ATT |
          Intervention # Endline | 0.609 [0.152,1.067]
          Subpopulation ATTs |
          Age (categories) |
          15-17 | 0.589 [0.090,1.088]
          18-19 | 0.619 [0.164,1.074]
          Wealth quintile |
          Very poor | 0.678 [0.231,1.124]
          Poor | 0.560 [-0.110,1.230]
          Averga | 0.748 [0.401,1.095]
          Rich | 0.495 [-0.069,1.059]
          Very rich | 0.574 [0.049,1.100]
          -----------------------------------------------
          * p<.05
          Thank you for the assistance. I am just wondering why the stars are not showing when I applied to the original dataset where I expect stars to show. Below is an output of the results from the original data set.
          Code:
          -----------------------------------------------
                                   |         ATT [95% CI]
          -------------------------+---------------------
          Main ATT                 |                     
            Intervention # Endline | 0.455 [0.305, 0.605]
          Subpopulation ATTs       |                     
            Age(categories)        |                     
              15-17                | 0.460 [0.307, 0.614]
              18-19                | 0.453 [0.303, 0.603]
            Wealth quintile        |                     
              Very poor            | 0.461 [0.309, 0.613]
              Poor                 | 0.462 [0.311, 0.613]
              Averga               | 0.464 [0.313, 0.615]
              Rich                 | 0.453 [0.301, 0.605]
              Very rich            | 0.438 [0.290, 0.587]
          -----------------------------------------------
          * p<.05

          Comment


          • #6
            Originally posted by Hemanshu Kumar View Post
            You can add this code at the end of yours:
            Never mind with the stars problem. I have resolved it. I was calling _r_b instead of _r_p. Thanks.

            Code:
            collect stars _r_p 0.05 "*", attach(_r_b) shownote
            
            My title
            ------------------------------------------------
                                     |          ATT [95% CI]
            -------------------------+----------------------
            Main ATT                 |                      
              Intervention # Endline | 0.455* [0.305, 0.605]
            Subpopulation ATTs       |                      
              Age(categories)        |                      
                15-17                | 0.460* [0.307, 0.614]
                18-19                | 0.453* [0.303, 0.603]
              Wealth quintile        |                      
                Very poor            | 0.461* [0.309, 0.613]
                Poor                 | 0.462* [0.311, 0.613]
                Averga               | 0.464* [0.313, 0.615]
                Rich                 | 0.453* [0.301, 0.605]
                Very rich            | 0.438* [0.290, 0.587]
            ------------------------------------------------
            * p<.05

            Comment

            Working...
            X