Announcement

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

  • Loop

    Hello,

    I have a very simple question but I can't find a working solution in the Stata help section.

    I have a dataset and I want to draw a graph for all regions of my country.

    I managed to get a graph using twoway line var year, sort for the entire country. Now I'd like to do the same thing for each region. The variable region has codes, like 001,A1, R3,... as region identifiers.

    I could to that with

    preserve
    keep if region="A1"
    twoway line ....
    restore

    And repeat this for all region,

    However, I was wondering: is there a code to do that more easily?


    Thanks a lot!



  • #2
    Code:
    twoway line ..., by(region)

    Comment


    • #3
      Thank you so much! I exploit the opportunity for an unrelated follow-up question: doing the above, I get an error when I try to drop some regions, because of type mismatch... my regions are in a format %9s.

      How can I drop let's say region 00?

      Both
      drop if region=="00"
      drop if region="0"
      do not work...

      Thanks!

      Comment


      • #4
        No; please start a new thread with a different question, and first read https://www.statalist.org/forums/help#stata to find out how to give us a data example.

        The only certainty here is that you need == not = to testt for equality. Why == "00" doesn't work is impossible to say without a data example.

        Comment

        Working...
        X