Announcement

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

  • Graphing Regression Discontinuity design on Stata

    Hi everyone,

    I am having issues graphing a regression discontinuity in Stata.

    My dataset is the following:

    HiscamP year treated |
    |---------------------------|
    1. | 42.84128 1862 0 |
    2. | 43.88376 1862 0 |
    3. | 43.422 1863 0 |
    4. | 44.46448 1863 0 |
    5. | 44.15967 1864 0 |
    |---------------------------|
    6. | 45.20215 1864 0 |
    7. | 43.7359 1865 0 |
    8. | 44.77838 1865 0 |
    9. | 42.87267 1866 0 |
    10. | 43.91515 1866 0 |
    |---------------------------|
    11. | 42.82558 1867 0 |
    12. | 43.86806 1867 0 |
    13. | 43.0924 1868 0 |
    14. | 44.13488 1868 0 |
    15. | 44.23815 1869 0 |
    |---------------------------|
    16. | 45.28062 1869 0 |
    17. | 44.3794 1870 0 |
    18. | 45.42188 1870 0 |
    19. | 44.12828 1871 0 |
    20. | 45.17076 1871 0 |
    |---------------------------|
    21. | 48.19841 1872 1 |
    22. | 49.07626 1872 1 |
    23. | 47.75099 1873 1 |
    24. | 48.62885 1873 1 |
    25. | 47.60185 1874 1 |
    |---------------------------|
    26. | 48.47971 1874 1 |
    27. | 47.64446 1875 1 |
    28. | 48.52232 1875 1 |
    29. | 47.74034 1876 1 |
    30. | 48.61819 1876 1 |
    |---------------------------|
    31. | 47.86817 1877 1 |
    32. | 48.74603 1877 1 |
    33. | 48.12384 1878 1 |
    34. | 49.00169 1878 1 |
    35. | 48.33689 1879 1 |
    |---------------------------|
    36. | 49.21475 1879 1 |
    37. | 48.73105 1880 1 |
    38. | 49.60891 1880 1 |
    39. | 49.67915 1881 1 |
    40. | 50.55701 1881 1 |
    |---------------------------|
    41. | 48.51799 1882 1 |
    42. | 49.39585 1882 1 |
    +---------------------------+

    .
    Essentially, I am trying to produce a scatter graph for the dataset above that includes two lines of best fit, one for the years that experienced the treatment and one for the years that did not receive the treatment.

    I have tried the following lines of code but they return "error 198 invalid syntax":

    Attempted lines

    graph twoway (lfit HiscamP year if treated=1) (scatter HiscamP year if treated=1
    > )

    twoway (lfit HiscamP year if treated=1)


    In essence, I am trying to add two lines of best fit to the graph below. One for the years up to and including 1871 and one for the following years



    Thank you in advance!

  • #2


    This is the previously mentioned graph!

    Thanks again!

    Comment


    • #3
      Welcome to Statalist. There is no visible graph in #2. As recommended in the FAQs, images should be uploaded in .png format. Also, your data in #1 is not usable as is, please use dataex to present it again (see FAQ Advice #12 for more details). To do this, copy and paste the result of the following:

      Code:
      dataex HiscamP year treated

      Comment


      • #4
        Hi there, thank you for your response!

        I have completed the above changes.

        Best Wishes,

        James

        Click image for larger version

Name:	HiscamP year scatter .png
Views:	1
Size:	31.5 KB
ID:	1618945

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input float HiscamP int year float treated
        42.84128 1862 0
        43.88376 1862 0
          43.422 1863 0
        44.46448 1863 0
        44.15967 1864 0
        45.20215 1864 0
         43.7359 1865 0
        44.77838 1865 0
        42.87267 1866 0
        43.91515 1866 0
        42.82558 1867 0
        43.86806 1867 0
         43.0924 1868 0
        44.13488 1868 0
        44.23815 1869 0
        45.28062 1869 0
         44.3794 1870 0
        45.42188 1870 0
        44.12828 1871 0
        45.17076 1871 0
        48.19841 1872 1
        49.07626 1872 1
        47.75099 1873 1
        48.62885 1873 1
        47.60185 1874 1
        48.47971 1874 1
        47.64446 1875 1
        48.52232 1875 1
        47.74034 1876 1
        48.61819 1876 1
        47.86817 1877 1
        48.74603 1877 1
        48.12384 1878 1
        49.00169 1878 1
        48.33689 1879 1
        49.21475 1879 1
        48.73105 1880 1
        49.60891 1880 1
        49.67915 1881 1
        50.55701 1881 1
        48.51799 1882 1
        49.39585 1882 1
        end

        Comment


        • #5
          Thanks for the data example.

          Code:
          set scheme s1color
          tw (scatter HiscamP year if treated, xtitle("") leg(order(1 "Treated" 2 "Control"))) ///
          (scatter HiscamP year if !treated) (lfit HiscamP year if treated, lcolor(navy)) ///
          (lfit HiscamP year if !treated, lcolor(red))
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	50.9 KB
ID:	1618987

          Comment

          Working...
          X