Announcement

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

  • How to do graphs by groups?

    Hello,

    I have the dataset below and I would like to have a picture for each "territory" where I could see the dots for each variable ("tfertrate" and "gini_imprents") over the year. I would like to have two y axis with a proper scale for each variable and with the name of the "territory" in the upper right side of each graph.
    Can you help me with this?
    \Thank you in advance.

    ​​​​​​
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str10 territory int year long(tfertrate gini_imprents)
    "Centro (I)" 1999  3  .
    "Isole"      1999 21  .
    "Italy"      1999 10  .
    "Nord-est"   1999  2  .
    "Nord-ovest" 1999  1  .
    "Sud"        1999 23  .
    "Centro (I)" 2000  4  .
    "Isole"      2000 19  .
    "Italy"      2000 13  .
    "Nord-est"   2000  8  .
    "Nord-ovest" 2000  5  .
    "Sud"        2000 24  .
    "Centro (I)" 2001  3  .
    "Isole"      2001 18  .
    "Italy"      2001 12  .
    "Nord-est"   2001  8  .
    "Nord-ovest" 2001  6  .
    "Sud"        2001 23  .
    "Centro (I)" 2002  7  .
    "Isole"      2002 17  .
    "Italy"      2002 14  .
    "Nord-est"   2002 12  .
    "Nord-ovest" 2002  9  .
    "Sud"        2002 21  .
    "Centro (I)" 2003  9 28
    "Isole"      2003 21 52
    "Italy"      2003 16 42
    "Nord-est"   2003 13 10
    "Nord-ovest" 2003 11 27
    "Sud"        2003 23 45
    "Centro (I)" 2004 16 25
    "Isole"      2004 21 54
    "Italy"      2004 21 39
    "Nord-est"   2004 22  8
    "Nord-ovest" 2004 19 23
    "Sud"        2004 24 42
    "Centro (I)" 2005 15 21
    "Isole"      2005 21 53
    "Italy"      2005 20 36
    "Nord-est"   2005 23  8
    "Nord-ovest" 2005 19 23
    "Sud"        2005 21 41
    "Centro (I)" 2006 20 13
    "Isole"      2006 21 46
    "Italy"      2006 24 29
    "Nord-est"   2006 27  4
    "Nord-ovest" 2006 25 17
    "Sud"        2006 22 33
    "Centro (I)" 2007 22  9
    "Isole"      2007 21 37
    "Italy"      2007 26 25
    "Nord-est"   2007 31  2
    "Nord-ovest" 2007 30 11
    "Sud"        2007 23 32
    "Centro (I)" 2008 31 14
    "Isole"      2008 24 38
    "Italy"      2008 31 29
    "Nord-est"   2008 34  7
    "Nord-ovest" 2008 33 15
    "Sud"        2008 24 33
    "Centro (I)" 2009 28 12
    "Isole"      2009 24 36
    "Italy"      2009 31 28
    "Nord-est"   2009 35  2
    "Nord-ovest" 2009 35 21
    "Sud"        2009 24 32
    "Centro (I)" 2010 29 17
    "Isole"      2010 24 47
    "Italy"      2010 31 33
    "Nord-est"   2010 35  6
    "Nord-ovest" 2010 36 19
    "Sud"        2010 24 35
    "Centro (I)" 2011 30 24
    "Isole"      2011 22 41
    "Italy"      2011 29 33
    "Nord-est"   2011 33  7
    "Nord-ovest" 2011 33 18
    "Sud"        2011 22 35
    "Centro (I)" 2012 28 20
    "Isole"      2012 22 49
    "Italy"      2012 29 35
    "Nord-est"   2012 34  6
    "Nord-ovest" 2012 33 17
    "Sud"        2012 21 42
    "Centro (I)" 2013 26 20
    "Isole"      2013 18 48
    "Italy"      2013 26 31
    "Nord-est"   2013 32  3
    "Nord-ovest" 2013 32 16
    "Sud"        2013 18 31
    "Centro (I)" 2014 25 16
    "Isole"      2014 21 51
    "Italy"      2014 25 30
    "Nord-est"   2014 31  1
    "Nord-ovest" 2014 31 15
    "Sud"        2014 18 28
    "Centro (I)" 2015 21 29
    "Isole"      2015 19 50
    "Italy"      2015 23 36
    "Nord-est"   2015 29  5
    end
    format %ty year
    label values tfertrate tfertrate
    label def tfertrate 1 "1,13", modify
    label def tfertrate 2 "1,15", modify
    label def tfertrate 3 "1,16", modify
    label def tfertrate 4 "1,17", modify
    label def tfertrate 5 "1,18", modify
    label def tfertrate 6 "1,19", modify
    label def tfertrate 7 "1,2", modify
    label def tfertrate 8 "1,21", modify
    label def tfertrate 9 "1,22", modify
    label def tfertrate 10 "1,23", modify
    label def tfertrate 11 "1,24", modify
    label def tfertrate 12 "1,25", modify
    label def tfertrate 13 "1,26", modify
    label def tfertrate 14 "1,27", modify
    label def tfertrate 15 "1,28", modify
    label def tfertrate 16 "1,29", modify
    label def tfertrate 17 "1,3", modify
    label def tfertrate 18 "1,31", modify
    label def tfertrate 19 "1,32", modify
    label def tfertrate 20 "1,33", modify
    label def tfertrate 21 "1,34", modify
    label def tfertrate 22 "1,35", modify
    label def tfertrate 23 "1,36", modify
    label def tfertrate 24 "1,37", modify
    label def tfertrate 25 "1,38", modify
    label def tfertrate 26 "1,39", modify
    label def tfertrate 27 "1,4", modify
    label def tfertrate 28 "1,41", modify
    label def tfertrate 29 "1,42", modify
    label def tfertrate 30 "1,43", modify
    label def tfertrate 31 "1,44", modify
    label def tfertrate 32 "1,45", modify
    label def tfertrate 33 "1,48", modify
    label def tfertrate 34 "1,49", modify
    label def tfertrate 35 "1,5", modify
    label def tfertrate 36 "1,51", modify
    label values gini_imprents gini_imprents
    label def gini_imprents 1 "0,253", modify
    label def gini_imprents 2 "0,254", modify
    label def gini_imprents 3 "0,255", modify
    label def gini_imprents 4 "0,257", modify
    label def gini_imprents 5 "0,26", modify
    label def gini_imprents 6 "0,261", modify
    label def gini_imprents 7 "0,262", modify
    label def gini_imprents 8 "0,265", modify
    label def gini_imprents 9 "0,267", modify
    label def gini_imprents 10 "0,271", modify
    label def gini_imprents 11 "0,273", modify
    label def gini_imprents 12 "0,274", modify
    label def gini_imprents 13 "0,275", modify
    label def gini_imprents 14 "0,276", modify
    label def gini_imprents 15 "0,277", modify
    label def gini_imprents 16 "0,278", modify
    label def gini_imprents 17 "0,279", modify
    label def gini_imprents 18 "0,28", modify
    label def gini_imprents 19 "0,281", modify
    label def gini_imprents 20 "0,282", modify
    label def gini_imprents 21 "0,284", modify
    label def gini_imprents 23 "0,286", modify
    label def gini_imprents 24 "0,287", modify
    label def gini_imprents 25 "0,288", modify
    label def gini_imprents 27 "0,292", modify
    label def gini_imprents 28 "0,293", modify
    label def gini_imprents 29 "0,294", modify
    label def gini_imprents 30 "0,295", modify
    label def gini_imprents 31 "0,296", modify
    label def gini_imprents 32 "0,297", modify
    label def gini_imprents 33 "0,298", modify
    label def gini_imprents 35 "0,301", modify
    label def gini_imprents 36 "0,303", modify
    label def gini_imprents 37 "0,304", modify
    label def gini_imprents 38 "0,305", modify
    label def gini_imprents 39 "0,306", modify
    label def gini_imprents 41 "0,308", modify
    label def gini_imprents 42 "0,31", modify
    label def gini_imprents 45 "0,315", modify
    label def gini_imprents 46 "0,317", modify
    label def gini_imprents 47 "0,32", modify
    label def gini_imprents 48 "0,321", modify
    label def gini_imprents 49 "0,322", modify
    label def gini_imprents 50 "0,323", modify
    label def gini_imprents 51 "0,325", modify
    label def gini_imprents 52 "0,327", modify
    label def gini_imprents 53 "0,329", modify
    label def gini_imprents 54 "0,338", modify

  • #2
    The data are mangled. It's a virtue of dataex to make that clear. You have pushed measurements through encode when destring was needed. This is a common mistake. The help for encode warns prominently

    Do not use encode if varname contains numbers that merely happen to be stored as strings; instead, use generate newvar = real(varname) or
    destring; see real() or [D] destring.

    More on the point at https://www.stata-journal.com/articl...article=dm0098

    Here are your first steps to fix that.

    Code:
    decode gini_imprents, gen(Gini)
    decode tfertrate, gen(fertility)
    destring Gini fertility, replace dpcomma 
    
    line  fertility Gini year, by(territory)
    Messing around with double y scales is beyond my inclinations, so I leave that open. But Gini is approximately flat while fertility rate is not, so I doubt that there is any relationship to discover or uncover.

    Comment

    Working...
    X