Announcement

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

  • How to add two separate values to a graph that plots same variable over time?

    Hello,
    I have a dataset for 1 country that shows the trend for multiple indicators from 2000-2020. I have plotted the trend for each indicator using time series but now I want to add two data points that correspond to 2 other variables ("lastvalueASP" and "lastvalueLCN") on their corresponding year (according to "lastyearASP" and "lastyearLCN" respectively). I initially tried to use sparklines but it did not allow me to add the extra data points.

    My final goal is to have the trend for each indicator (e.g. SE.SEC.CMPT.LO.FE.ZS) and then 2 points that show where the other 2 variables ("lastvalueASP" and "lastvalueLCN") are on the same plot. Does anyone have any advice or knows how to create such visual? Greatly appreciate any guidance!

    Here is a sample of my data:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str20 indicatorcode double lastvalue int(lastyear year) double value int lastyearASP double lastvalueASP int lastyearLCN double lastvalueLCN
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2000                . 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2001                . 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2002                . 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2003 64.5569610595703 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2004 84.2009124755859 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2005 82.3529434204102 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2006                . 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2007                . 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2008                . 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2009                . 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2010 117.277992248535 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2011                . 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2012 95.3093795776367 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2013 93.7818603515625 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2014 93.6192474365234 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2015 102.470458984375 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2016  113.38410949707 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2017  104.44938659668 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2018 96.3718795776367 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2019                . 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.FE.ZS" 96.37187957763672 2018 2020                . 2019 102.13663482666016 2020 82.33609008789063
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2000                . 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2001                . 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2002                . 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2003  53.166820526123 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2004 61.1711692810059 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2005 66.8177719116211 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2006                . 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2007                . 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2008                . 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2009                . 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2010 110.536041259766 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2011                . 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2012 90.9176025390625 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2013 89.0699920654297 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2014 89.7233200073242 2019 102.65520477294922 2020 77.62348937988281
    "SE.SEC.CMPT.LO.MA.ZS" 88.03778076171875 2018 2015 96.2474594116211 2019 102.65520477294922 2020 77.62348937988281
    end

  • #2
    Like this?
    Code:
    line value year   /// 
        || scatter  lastvalueASP lastyearASP  /// 
        || scatter  lastvalueLCN lastyearLCN  /// 
        || , by(indicator)

    Comment


    • #3
      Unfortunately I got that || is not correct

      I modified it too using the following

      Code:
       line value year   ///    
       || scatter  lastvalueASP lastyearASP  ///    
       || scatter  lastvalueLCN lastyearLCN  ///    
       || , by(indicatorcode)
      Any other suggestions please?
      Last edited by Daniel McAdams; 24 Nov 2022, 06:57.

      Comment


      • #4
        did you try Scott's code in a do file? it will not work interactively; if you want to do it interactively, erase the "///" on each of the first 3 lines - but better to use a do file

        Comment


        • #5
          Thank you SO much, Scott Merryman!! You were correct, it worked in the do file Rich Goldstein. Thank you!

          Comment

          Working...
          X