Announcement

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

  • Plotting result of table function

    Sorry a very basic question.

    To get a table I run:

    table year city [pw=E], c(mean W)

    and get the below. Is there a way to then plot a line graph with year on the x axis and data on y axis ? I tried plotting direct but no luck either.

    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	19.3 KB
ID:	1611510





  • #2
    In Stata 16 and previous versions, table does not store any displayed results. You therefore have to recreate the results yourself. Without weights, this is straightforward. I have never tried to do it with weights. The best strategy will be to give a data example using dataex (see FAQ Advice #12) and someone in the forum may be able to help you out. The other way is to copy these values and create 3 variables, then

    Code:
    line A B year

    Comment


    • #3
      Code:
      collapse W [pw=E] , by(year city) 
      
      line W year if city == "A" || line W year if city == "B", sort legend(order(1 "A" 2 "B"))
      is a guess but some details hinge on ambiguities e.g. whether city is a string variable or a numeric variable with value labels. And are your cities really called "A" and "B"?

      Comment


      • #4
        that is totally awesome (and works!). My cities aren't really A and B, the above is just a toy version of something much larger

        Comment


        • #5
          That's fine, but the advice would be different for many more cities. It would probably be to set up xtset and go for xtline.

          Comment

          Working...
          X