Announcement

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

  • Use lgraph to draw a parellel trend graph.

    Hi,I am a new Stata user. I am using the hospdd.dta to run a DID program. I want to use the code lgraph to generates the parellel trend.

    Here is my data
    Click image for larger version

Name:	_20220217194529.jpg
Views:	1
Size:	107.1 KB
ID:	1650686


    I use the code: lgraph satis month, by(procedure) to generate the following graph:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	52.4 KB
ID:	1650687


    But the correct graph should be like this, it seems that the first three months are disappear for the control group.

    Click image for larger version

Name:	226712491_15_20210721093423286.png
Views:	1
Size:	27.0 KB
ID:	1650688


    What should be the correct code? Really appreciate your answers!

  • #2
    I also following this code to generate the parellel trend graph:

    bysort month procedure: egen mean_satis = mean(satis)

    twoway (connected mean_satis month if procedure==0, msize(medium) msymbol(circle) lwidth(thin) lpattern(dash)) (connected mean_satis month if procedure==1, msize(medium) msymbol(circle) lwidth(thin) lpattern(solid)), graphregion(color(white)) xline(3,lc(red) lpattern(solid)) ytitle(Patient satisfaction score, size(medium)) xlabel(1(1)7,labsize(medium)) ylabel(3.4(0.2)4.4,labsize(medium)) legend(label(1 "Control") label(2 "Treatment") size(medium))

    And get this graph:

    Click image for larger version

Name:	Graph2.png
Views:	1
Size:	35.9 KB
ID:	1650715

    I also can not plotted the treatment group from the first three month.

    Comment


    • #3
      I don't want to see a picture, please use dataex as the FAQ says to show us your real dataset, one that I or someone else can actually work with.

      Comment


      • #4
        There has not been a single occurrence in your data picture! where procedure=1 and month is less than 4. Which is the reason your 'treatment' (procedure=1) group has a line starting from month=4. What is the data source of the claimed 'correct' graph? Are both graphs being generated from the same data? I don't think so. Show the data example again using -dataex- ideally with a blend of procedure and month so that we can see what is happening here. Please don't use picture for data example, use -dataex- as suggested in #3
        Roman

        Comment


        • #5
          Hi Jacky,

          I would try the following code

          Code:
          webuse hospdd, clear
          bysort hospital: egen treated = max(procedure)
          lgraph satis month, by(treated)
          Jared and Roman give you good advice. To try to get better help, providing reproducible examples, data and code, is important. I just happen to be a bit familiar with the data you are mentioning. The key here is that the variable procedure is the interaction of the treated group and the post-intervention period. You just need to define a treatment group to reproduce the graph. Welcome to Stata and to Statalist.
          Last edited by Enrique Pinzon (StataCorp); 18 Feb 2022, 09:46.

          Comment


          • #6
            Originally posted by Jared Greathouse View Post
            I don't want to see a picture, please use dataex as the FAQ says to show us your real dataset, one that I or someone else can actually work with.
            Hi Jared, Thank you so much! Now I know how to post the data.

            Comment


            • #7
              Originally posted by Roman Mostazir View Post
              There has not been a single occurrence in your data picture! where procedure=1 and month is less than 4. Which is the reason your 'treatment' (procedure=1) group has a line starting from month=4. What is the data source of the claimed 'correct' graph? Are both graphs being generated from the same data? I don't think so. Show the data example again using -dataex- ideally with a blend of procedure and month so that we can see what is happening here. Please don't use picture for data example, use -dataex- as suggested in #3
              Hi Roman, Thank you for the suggestion!

              Comment


              • #8
                Originally posted by Enrique Pinzon (StataCorp) View Post
                Hi Jacky,

                I would try the following code

                Code:
                webuse hospdd, clear
                bysort hospital: egen treated = max(procedure)
                lgraph satis month, by(treated)
                Jared and Roman give you good advice. To try to get better help, providing reproducible examples, data and code, is important. I just happen to be a bit familiar with the data you are mentioning. The key here is that the variable procedure is the interaction of the treated group and the post-intervention period. You just need to define a treatment group to reproduce the graph. Welcome to Stata and to Statalist.
                Hi Enrique, Thank you so much for your code! I can generate the same graph as yours. Really appreciate it!

                Comment

                Working...
                X