Announcement

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

  • Legends in didregress trend plots

    Hi,

    I am using really basic DID regression in my empirical analysis. I want to change how my legends appear in trend plot. However, despite what the documentation says, I can not change the legends - for instance, if I want to turn the legends off. Here is my code:

    xtdidregress (turnout_p) (interaction_buildings_zero_2021) if all == 1, group(voting_area_id) time(year)
    estat trendplots, legend(off)

    Any ideas on how can I fix this?

    Thank you!

  • #2
    It should be straightforward, but we need a reproducible example nonetheless (see FAQ Advice #12 for details).

    Comment


    • #3
      Sorry. So, I am using Stata 18.0 and here is an example code to produce the trend plot:

      ***
      clear

      input str10 voting_area year turnout_p interaction_buildings_zero_2021
      1 2019 0.60 0
      1 2020 0.62 0
      1 2021 0.65 0
      2 2019 0.55 0
      2 2020 0.57 0
      2 2021 0.58 1
      3 2019 0.70 0
      3 2020 0.72 0
      3 2021 0.75 1
      end

      encode voting_area, gen(voting_area_id)

      xtset voting_area_id year

      eststo: xtdidregress (turnout_p) (interaction_buildings_zero_2021), group(voting_area_id) time(year)
      estat trendplots

      ***


      So my question is, how can I change the legend text (now just Control and Treatment)? or the text of the main title (currently default text)?
      Click image for larger version

Name:	trendplot_example.png
Views:	1
Size:	69.9 KB
ID:	1751236
      Attached Files

      Comment


      • #4
        As -byopts()- are not allowed, ask for individual legends and then turn these off.

        Code:
        clear
        input str10 voting_area year turnout_p interaction_buildings_zero_2021
        1 2019 0.60 0
        1 2020 0.62 0
        1 2021 0.65 0
        2 2019 0.55 0
        2 2020 0.57 0
        2 2021 0.58 1
        3 2019 0.70 0
        3 2020 0.72 0
        3 2021 0.75 1
        end
        
        encode voting_area, gen(voting_area_id)
        xtset voting_area_id year
        eststo: xtdidregress (turnout_p) (interaction_buildings_zero_2021), group(voting_area_id) time(year)
        estat trendplots, nocommonlegend leg(off)
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	39.0 KB
ID:	1751250

        Comment


        • #5
          Thank you very much! How could I change the legend's text if I want to have the same legend for both of the graphs? In addition, how could I change the title's text, which is "Graphical diagnostics for parallel trends" at the moment?

          Comment


          • #6
            Code:
            help estat trendplots
            and see the -legendfrom()- option combined with standard options for changing legend labels.

            Comment

            Working...
            X