Announcement

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

  • Graph twoway line separately by different countries

    Hello,

    I have the following database:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(Ccode year) float wanted
     3 1997  2
     3 1998  1
     3 1999  6
     3 2000  5
     3 2001  9
     3 2002  7
     3 2003  5
     3 2004  5
     3 2005  4
     3 2006  6
     3 2007  6
     3 2008  8
     3 2009  9
     3 2010  5
     3 2011 15
     3 2012  9
     3 2013 14
     3 2014 17
     3 2015 15
     3 2016 18
     3 2017 22
     3 2018 41
     3 2019 35
     3 2020 58
     3 2021 41
     6 1997  4
     6 1998  6
     6 1999  5
     6 2000  6
     6 2001  5
     6 2002  2
     6 2003  2
     6 2004  3
     6 2005  2
     6 2006  2
     6 2007  4
     6 2008  2
     6 2009  3
     6 2010  1
     6 2011  3
     6 2012  4
     6 2013  4
     6 2014  1
     6 2015  2
     6 2016  8
     6 2017  7
     6 2018  9
     6 2019  4
     6 2020 19
     6 2021 30
    25 1997  0
    25 1998  0
    25 1999  0
    25 2000  0
    25 2001  1
    25 2002  0
    25 2003  0
    25 2004  2
    25 2005  0
    25 2006  0
    25 2007  1
    25 2008  0
    25 2009  0
    25 2010  0
    25 2011  0
    25 2012  0
    25 2013  0
    25 2014  1
    25 2015  6
    25 2016  6
    25 2017 14
    25 2018  8
    25 2019 20
    25 2020 34
    25 2021 28
    30 1997  0
    30 1998  0
    30 1999  0
    30 2000  0
    30 2001  0
    30 2002  0
    30 2003  0
    30 2004  1
    30 2005  0
    30 2006  0
    30 2007  1
    30 2008  1
    30 2009  1
    30 2010  0
    30 2011  0
    30 2012  0
    30 2013  0
    30 2014  0
    30 2015  0
    30 2016  0
    30 2017  0
    30 2018  1
    30 2019  1
    30 2020  1
    30 2021  2
    end
    I would like to draw a graph of each country (variable Ccode) where in my horizontal axis appears the variable "year" and in the vertical axis the variable "wanted". I would like to have a different graph for each country, that is, if I have 30 countries, I would like to have 30 different graphs.

    I am doing with the following command:

    Code:
    twoway line wanted year, by(Ccode)
    But it does not work because it is drawing (separately) but in the same graph. I would like to have them separately but in different graphs. Can you help me with it?


    On the other hand, I also have a second question. If at some moment I would like to graph two/three countries in the same graph, that is, three lines in the same graph (one for each country). For example, countries 3, 6 and 25, is it possible to do it?

    Thank you,

    Diego.
    Last edited by Diego Malo; 15 Dec 2021, 05:52.

  • #2
    Code:
    line wanted year, by(Ccode, yrescale) 
    
    separate wanted,by(Ccode) veryshortlabel 
    line wanted3 wanted6 wanted25 year
    may help. I can't see any advantage to separate graphs here.

    Comment


    • #3
      Thank you Nick Cox for your comment. The advantage is that in the complete dataset I have 54 countries, so it's a bit confuse to see all the countries in the same graph. They are a bit small.

      Comment


      • #4
        Indeed; 54 countries is a lot You might show say 13 to 14 in each of 4 panels.

        Comment


        • #5
          Thank you for your comment. When you mean in 4 panels, do you refer in the same graph with 4 panels and 12-13 countries per panel? Is it possible to do it? I am starting with Stata, sorry if the questions are so easy.

          Comment

          Working...
          X