Announcement

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

  • Help on esttab keep option

    I am running several models and only wanted to export selected regression coefficients to excel. I created a macro for the selected regression coefficients that I wanted to export.

    I am trying to use this macro in the keep option in esttab

    Code:
    global m1did "1.treat#1.post"
    
    esttab y1 y2 y3 using table2.csv, b(3) se(3) title(Regression coefficients on DID model) star(# 0.1 * 0.05 ** 0.01 *** 0.001) replace bracket keep(`m1did')
    However the excel exported contained all the regression coefficients, not just the coefficients on 1.treat#1.post

    I tried to change to keep(`"1m1did'"') it gave me empty cells

    What am I doing wrong in using the macro variable for the keep option?

    Thanks!

    Rui

  • #2
    I have already pointed out in https://www.statalist.org/forums/for...macro-variable that you are mixing up global and local macro syntax. So, let's take that as read please.

    Comment


    • #3
      Hi Nick,

      I read your post and deleted the variable from the macro in this post. sorry if I did not get what you meant.

      Thanks!

      Rui

      Comment


      • #4
        Nick,

        I got what you meant. I changed the global to local to define the macro. It did what i meant to do. Thank you so much!

        I did not realize that global and local made such a difference. I need to learn more about it!

        Comment


        • #5
          Nick already provided code that should fix your problem in the other thread. Right now the local macro m1did is not evaluating because you haven't defined it. You defined a global macro but are referencing a local macro in your esttab command. So Stata is evaluating that macro as a blank and keeping all variables.

          To demonstrate the difference to yourself try running this
          Code:
          local m1= "this is a local macro"
          global m1= "this is a global macro"
          
          display "`m1'"
          
          display "$m1"
          Also to get a link to the full documentation on macros with examples and other helpful information type (and click on the remarks and examples link)
          Code:
          help macro

          Comment


          • #6
            Sarah,

            Thanks for explaining the difference to me! I will read more on macro using the stata help.

            Rui

            Comment


            • #7
              I am still curious why when I use local macro the program gave me what I wanted, but not a global macro?

              this is the program which gave me only the coeffients for 1.treat#1.post
              Code:
              local m1did "1.treat#1.post"
              
              esttab y1 y2 y3 using table2.csv, b(3) se(3) title(Regression coefficients on DID model) star(# 0.1 * 0.05 ** 0.01 *** 0.001) replace bracket keep(`m1did')
              but if i use
              Code:
              global m1did "1.treat#1.post"
              
              esttab y1 y2 y3 using table2.csv, b(3) se(3) title(Regression coefficients on DID model) star(# 0.1 * 0.05 ** 0.01 *** 0.001) replace bracket keep($m1did)
              the program gave me all the coeffients

              Comment

              Working...
              X