Announcement

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

  • A question on using macro variable

    I am running several models and only wanted to export selected regression coefficients to excel. So I created a macro variable for the selected regression coefficients since in different models they are different.

    global m1did "1.treat#1.post"

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

    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
    In Stata global and local macros are called ... macros, not variables. https://www.stata.com/statalist/arch.../msg01258.html says more.

    More crucially, for you the problem is using local syntax to refer to a global macro.

    See e.g. 18.3 in [U] under pdf documentation.


    I think what you seek is

    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)
    although I can't comment on whether that is right for what you want.

    esttab is community-contributed, so you are asked to explain where you got it from (FAQ Advice #12).

    Comment


    • #3
      Nick,

      Thank you for helping and the comments! I am still new to stata and I have a lot to learn!
      What is trying to do is to only export the regression coefficients on 1.treat#1.post. I tried your command but it still gave me regression coefficients for all the variables in the model.

      Since I am new, i am curious on how you get the stata format code here? I copied and pasted the lines from stata and they did not look pretty. I used ssc install estout to get esttab.

      Thanks!

      Rui

      Comment


      • #4
        Formatting: Just (please) read https://www.statalist.org/forums/help#stata as every new message prompt asks you to do.

        esttab: I already said " I can't comment on whether that is right for what you want" and there was no false modesty there. esttab is an excellent command I have never used. So, I suggest that you start a new thread with esttab in the title as people knowing about it won't necessarily read this thread.

        Comment


        • #5
          Nick,

          Thanks! I will submit a new question.

          Rui

          Comment

          Working...
          X