Announcement

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

  • How to send frame results to Excel

    Hello everyone,

    I am totally a beginner at Stata.
    I would like to drop certain variables before further analyses and am trying to find ways to list up the dropped variables and send them to Excel.
    I managed to list up the dropped variables as follows, but could anyone suggest the way to send these results (name, rho, and p-value of the dropped variables) to Excel?

    Code:
    *drop prot* varibles if prot* significantly correlates with age and list up the dropped variables
    frame create results str32 vble long float(rho p)
    
    foreach var of varlist prot* {
        quietly spearman age `var'
        if r(p) < 0.05 frame post results ("`var'") (`r(rho)') (`r(p)')
        if r(p) < 0.05 drop `var'
    }
    
    frame results {
        format rho p %4.3f
        list, noobs clean
    }
    Thanks!

  • #2
    Any dataset can be sent to Excel using -export excel-. The manual examples are pretty easy to follow.

    Comment


    • #3
      Hi Leonardo,

      Thank you so much for your prompt suggestion. It was so helpful since I was trying to write a loop command with -putexcel- and it didn't work as expected.
      So I went through the manual examples of -export excel- and added several patterns of codes right after the code I previously posted but it gives me different error messages as follows.

      Code:
      export excel ("`var'") (`r(rho)') (`r(p)') using exporttest1 , sheet("testsheet1", replace)
      " invalid name
      r(198);
      Code:
      export excel "`var'" `r(rho)' `r(p)' using exporttest1 , sheet("testsheet1", replace)
      " invalid name
      r(198);
      Code:
      export excel `var' `r(rho)' `r(p)' using exporttest1 , sheet("testsheet1", replace)
      .047517109080651 invalid name
      r(198);
      Code:
      export excel using exporttest1 , sheet("testsheet1", replace)
      too many or no variables specified
      r(198);
      I think there might be some very basic grammatical errors, but I cannot identify them. Could you kindly help me solve the problem?

      Comment


      • #4
        Your last example is close to the mark. You will need to run that from the results frame to output the data to Excel. You can modify your code as follows and it should work (though untested).

        Code:
        frame results {
            format rho p %4.3f
            list, noobs clean
            export excel using myresults.xlsx, sheet("results"), replace
        }

        Comment


        • #5
          It worked! Thank you so much for all your help!!

          Comment


          • #6
            Glad it worked for you, and thanks for the thanks.

            Comment

            Working...
            X