Announcement

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

  • How to plot a figure with treatment and nontreatment after DID regression.

    Dear Statalists,

    I am trying to plot a figure after a difference-in-difference regression. The DID regression is as below.

    reg dependent i.year treatment treatment*post var1 var2

    After the regression, I want to plot a figure with two lines.
    Line 1 = mean(dependent) - _b[var1]*mean(var1) - _b[var2]*mean(var2), for treatment group through years.
    Line 2 = mean(dependent) - _b[var1]*mean(var1) - _b[var2]*mean(var2), for nontreatment group through years.
    These are actually "the mean of dependent variables" minus "the factors impacted by var1 and var2" for both treated and untreated groups through years. So, I tried the code as follows.

    egen depedent1=mean(depedent1) - _b[var1]*mean(var1) - _b[var2]*mean(var2), by(year), if treatment==1
    egen depedent2=mean(depedent1) - _b[var1]*mean(var1) - _b[var2]*mean(var2), by(year), if treatment==0

    Unfortunately, Stata reports "varlist not allowed". May I have your advice on how can I work on this?

    Thanks a lot,
    Chenli
    ​​​​​

  • #2
    Hello Chenli,
    when clicking on the #-symbol you can wrap your code in [/CODE] [CODE] and it will be easier to read. Also, example data with -dataex- supports others helping you.

    Concerning your regression, I think you should cluster the standard errors on the panel unit id, for instance:
    Code:
    regress variables, vce(cluster unitid)
    See more here: https://www.stata.com/manuals13/xtvce_options.pdf

    Besides this, you don't need to type "_b". Here is an example that I have from a tutorial that may be useful as a generel hint on how you can directly use regression results.
    Code:
    help predict
    regress dep indep
    predict dep_hat
    //COMPARISON
    graph twoway scatter dep indep || line dep_hat indep

    Last edited by Rebecca Water; 15 Oct 2018, 07:07.

    Comment


    • #3
      Edit: In general for the egen command, your if statement is in the wrong place, it should be before the comma:
      https://www.stata.com/manuals13/degen.pdf

      Comment


      • #4
        Hello Rebecca,

        Thank you very much for the help. Your suggestions work very well.

        Best wishes,
        Chenli

        Comment

        Working...
        X