Announcement

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

  • #16
    Dear Ali! Thank you very much! This worked very well!

    However, as Nick pointed out, there could be an issue if we have more than ten groups (districts), which is my case, unfortunately. How can I create a graph for only a subset of groups (districts)? I know exactly which groups I want to compare (based on economic/logical rationale).

    To sum, I just want a graph of 4 out of 12 panels (districts)


    I thank you for any further help!

    Comment


    • #17
      Dear Ali! Thank you very much! This worked very well!

      However, as Nick pointed out, there could be an issue if we have more than ten groups (districts), which is my case, unfortunately. How can I create a graph for only a subset of groups (districts)? I know exactly which groups I want to compare (based on economic/logical rationale).

      To sum, I just want a graph of 4 out of 12 panels (districts)


      I thank you for any further help!
      Originally posted by Ali Gokhan Yucel View Post

      Here is my suggestion.

      Code:
      clear
      input float year str1 province float total str1 district
      2003 "A" 62 "1"
      2004 "A" 45 "1"
      2005 "A" 43 "1"
      2003 "B" 65 "2"
      2004 "B" 50 "2"
      2005 "B" 64 "2"
      2003 "C" 70 "3"
      2004 "C" 60 "3"
      2005 "C" 75 "3"
      end
      
      
      egen id=group(district) , label
      
      xtset id year
      
      xtline total, overlay leg(off)

      Comment


      • #18
        As you mentioned in your initial post, you are working with panel data. It seems more practical to me to use xtline, as it eliminates the need for additional code to color the cross-sections (e.g., countries, firms, districts, etc.).

        If I understand correctly, you want to plot only specific districts from your panel. Why not use the | operator to specify which districts to include in the graph? Alternatively, the inlist() function might be even more convenient.

        To illustrate, I’ve expanded your dataset to include 12 districts over 3 years. Below is an example where I graph only districts 1, 3, 5, and 7.



        Code:
        clear
        input float year str1 province float(total district)
        2003 "A" 62  1
        2003 "B" 65  2
        2003 "C" 70  3
        2003 "D" 60  4
        2003 "E" 70  5
        2003 "F" 45  6
        2003 "G" 66  7
        2003 "H" 50  8
        2003 "I" 60  9
        2003 "J" 48 10
        2003 "K" 70 11
        2003 "L" 45 12
        2004 "A" 45  1
        2004 "B" 50  2
        2004 "C" 60  3
        2004 "D" 62  4
        2004 "E" 71  5
        2004 "F" 60  6
        2004 "G" 70  7
        2004 "H" 54  8
        2004 "I" 66  9
        2004 "J" 56 10
        2004 "K" 77 11
        2004 "L" 50 12
        2005 "A" 43  1
        2005 "B" 64  2
        2005 "C" 75  3
        2005 "D" 70  4
        2005 "E" 65  5
        2005 "F" 62  6
        2005 "G" 72  7
        2005 "H" 57  8
        2005 "I" 69  9
        2005 "J" 72 10
        2005 "K" 80 11
        2005 "L" 55 12
        end
        
        xtset district year
        
        xtline total if inlist(district, 1,3,5,7) , overlay leg(off)  xlab(2003/2005) xtitle("") text(76 2005 "3", size(*.6) col(orange)) text(44 2005 "1", size(*.6) col(green))
        Click image for larger version

Name:	image_36430.png
Views:	1
Size:	66.4 KB
ID:	1768577

        Comment


        • #19
          You can add an if qualifier such as

          Code:
          if inlist(district, 1, 2, 3, 4)
          to your existing code.

          My view is that xtline is a helpful convenience command -- but you can often do much better. Here is some sample code.

          Code:
          webuse grunfeld, clear 
          
          local labopts ms(none) mlabel(company) mlabsize(medlarge)
          
          forval c = 1/4 {
              local call `call' scatter invest year if year == 1954 & company == `c', `labopts' mlabcolor(stc`c')
              local call `call' || scatter invest year if year == 1935 & company == `c', `labopts' mlabpos(9) mlabcolor(stc`c')
              local call `call' || line invest year if company == `c', lcolor(stc`c') || 
          }
          
          `call' , ysc(log) yla(2000 1000 500 200 100 50 20) xsc(r(1934 .)) legend(off) xtitle("")

          Comment


          • #20
            Here's the graph:

            Click image for larger version

Name:	directlabel.png
Views:	1
Size:	72.5 KB
ID:	1768588

            Comment


            • #21
              I am very grateful to both Nick and Ali! It all worked out well for me!

              Comment

              Working...
              X