Announcement

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

  • When export to Excel, how to exclude one variable?

    I use manual item "Data to Excel Spreadsheet" from File---Export. The codes are:
    Code:
    export excel using "/Users/Documents/MedifyMD/Extracted.xlsx" if search2 > 0, sheet("boston+model") firstrow(variables)
    But I don't wanna search2 variable to be shown up in my Extracted.xlsx file. Is there a way to do that? In R, I know I can use "-search2", but I don't know how to do in Stata.

  • #2
    Code:
    preserve
        drop search2
        export excel using "/Users/Documents/MedifyMD/Extracted.xlsx" if search2 > 0, sheet("boston+model") firstrow(variables)
    restore

    Comment


    • #3
      Alternatively
      Code:
      . ds
      x  y  z
      
      . ds z, not
      x  y
      
      . local vars `r(varlist)'
      
      . display "`vars'"
      x y
      
      . export excel `vars' using gnxl.xlsx
      file gnxl.xlsx saved

      Comment


      • #4
        Originally posted by Sergiy Radyakin View Post
        Code:
        preserve
        drop search2
        export excel using "/Users/Documents/MedifyMD/Extracted.xlsx" if search2 > 0, sheet("boston+model") firstrow(variables)
        restore
        Hi, your method doesn't work. The error message pops out: search2 not found

        Comment


        • #5
          Try
          Code:
          preserve
          keep if search2>0
          drop search2
          export excel using "/Users/Documents/MedifyMD/Extracted.xlsx", sheet("boston+model") firstrow(variables)
          restore

          Comment

          Working...
          X