Announcement

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

  • Making a graph of points estimates for different models as a separate series in the same graph

    Hello. I am aiming to create a graph in Stata that displays two point estimates—corresponding to my variables Status and the interaction term StatusDistance —for each country. Additionally, I want these estimates, along with their confidence intervals, to be plotted on the x-axis, with each country represented on the y-axis.

    My original idea is to use coefplot. However, after reading and creating my code using this reference: from https://repec.sowi.unibe.ch/stata/co...g-started.html, I am not sure if that command can be used to obtain what I would like to have.

    This is the code I am using

    Code:
    levelsof iso3, local(countries)
    
    foreach c of local countries {
    
    reghdfe identity Status StatusDistance if iso3 == "`c'", abs(XXX) cluster(XXXX)
    estimates store country_`c'
    }
     
    coefplot (country_BEN, label(Benin) pstyle(p3))  ///
             (country_GHA, label(Ghana)  pstyle(p4))  ///
          , drop(_cons) xline(0) msymbol(S)
    And this is what I get:
    Click image for larger version

Name:	GraphStataList.png
Views:	1
Size:	31.4 KB
ID:	1775678




    However, I would like to reverse this, so that instead of having 'StatusNat' and 'StatusNat x DistanceF' on the y-axis, I want to have all my countries on the y-axis, with two point estimates for each country. Any ideas on how to achieve this with coefplot, or should I use another command?




    Last edited by Diego Malo; 10 Apr 2025, 06:41.

  • #2
    Similar question here: https://www.statalist.org/forums/for...t%C2%A0command
    Andrew Musau provide an answer.
    Code:
    coefplot (country_BEN country_GHA, label(Status) pstyle(p3))  ///
             (country_BEN country_GHA, label(StatusDistance)  pstyle(p4))  ///
             , aseq drop(_cons) xline(0) msymbol(S)
    Last edited by Chen Samulsion; 10 Apr 2025, 07:12. Reason: add aseq (asequation) option

    Comment


    • #3
      Thank you for your answer Chen Samulsion . I tried that code but it is not working, this is what is happening. Additionaly, I do not understand neither why I have "two" rectangles in the same line with that code.


      Click image for larger version

Name:	Graph2.png
Views:	1
Size:	30.9 KB
ID:	1775681



      Comment


      • #4
        Hi Diego Malo, no data to verify, but try this:
        Code:
        levelsof iso3, local(countries)
        
        foreach c of local countries {
            reghdfe identity Status StatusDistance if iso3 == "`c'", abs(XXX) cluster(XXXX)
            estimates store country_`c'
        }
         
        coefplot (country_BEN country_GHA, keep(Status) label(Status) pstyle(p3))  ///
                 (country_BEN country_GHA, keep(StatusDistance) label(StatusDistance) pstyle(p4))  ///
                 , aseq ylab("") drop(_cons) xline(0) msymbol(S)
        Code:
        sysuse auto
        
        levelsof foreign, local(country)
        
        foreach c of local country {
            reghdfe price weight length if foreign == `c', absorb(rep78)
            estimates store country_`c'
        }
         
        coefplot (country_0 country_1, keep(weight) label(weight) pstyle(p3))  ///
                 (country_0 country_1, keep(length) label(length) pstyle(p4))  ///
                 , aseq ylab("") drop(_cons) xline(0) msymbol(S)
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	115.7 KB
ID:	1775685
        Last edited by Chen Samulsion; 10 Apr 2025, 07:32. Reason: add keep option and use auto as an example

        Comment


        • #5
          Hi Chen Samulsion. Thanks a lot for your answer. I would love to add some data with dataex but with 100 obs my regressions are not working as I need variation in time and country.

          I tried your latest suggestion, and it has significantly improved the graph. However, each country now appears with four lines in the plot, whereas I expected only two per coefficient. Do you know why?

          Click image for larger version

Name:	Graph3.png
Views:	1
Size:	32.7 KB
ID:	1775687

          Comment


          • #6
            Use keep option to keep specified coefficients, see my modification in blue in #4. In each line of sentence, add keep(Status) and keep(StatusDistance) separately.

            Comment


            • #7
              Amazing. It works. Thanks a lot Chen Samulsion !!

              Comment


              • #8
                Diego Malo, you are welcome. Andrew Musau deserves your thanks. I just study and mimic his codes.

                Comment

                Working...
                X