Announcement

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

  • Help with collect commands

    Hello everyone, new to stata and will appreciate any help here.

    I have written a loop to run a regression and then below that, I have tried to use the collect commands to export the beta coefficient, p values and confidence intervals into an excel file but I seem to get the following error: Your layout specification does not uniquely match any items. One or more of the following dimensions might help uniquely match items: cmdset, coleq, imd, ethnicity, gender, workingdiagnosis.
    (collection default exported to file resulttable3.txt)

    My loop is below:

    local x "age i.gender i.ethnicity i.workingdiagnosis diseaseduration i.imd"
    foreach var of local x {
    regress painscore `var'
    collect get _r_b _r_p _r_ci
    collect dims
    collect layout (colname) (result[_r_b _r_p _r_ci])
    collect export resulttable3.txt, replace
    }

    The loop produces the necessary results in the stata results window but nothing seems to be getting exported.
    Last edited by Kola Adeniran; 20 Mar 2024, 06:38.

  • #2
    collect export resulttable3.txt, replace
    You are overwriting all previous results specifying the option -replace-, although the last regression should be outputted if it was successful. Try

    Code:
    local x "age i.gender i.ethnicity i.workingdiagnosis diseaseduration i.imd"
    foreach var of local x{
       local opt= cond("`x'"== "age", "replace", "append")
        regress painscore `var'
        collect get _r_b _r_p _r_ci
        collect dims
        collect layout (colname) (result[_r_b _r_p _r_ci])
        collect export resulttable3.txt, `opt'
    }
    Last edited by Andrew Musau; 20 Mar 2024, 12:16.

    Comment


    • #3
      Wow. Thank you so much. The code works perfectly.

      Comment

      Working...
      X