Announcement

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

  • Graph showing how the suicide rate changes over time

    Hi everyone,

    I'm currently completing my undergraduate dissertation, titled "The Macroeconomic Determinants of Mental Health". I'm using a country-level panel data set spanning 30 years to uncover how/if different elements of the macroeconomy affect the suicide rate and the prevalence of depression (my defendant variables). For my introduction, I would like to code a graph that shows how the suicide rate/prevalance of depression changes over time by income group. I've quickly drawn an example graph to show you the type of thing I am hoping to code:


    Click image for larger version

Name:	Screenshot 2021-04-22 at 18.03.44.png
Views:	1
Size:	73.7 KB
ID:	1605187

    I know the code for this is probably quite simple, but I've been playing around with the Graphics tab and still no luck

    Is anyone able to point me in the right direction, or provide some sample code?

    Thanks

  • #2
    It depends on what your data looks like. Can you give us an example? See the Statalist FAQ (link is in the black bar at the top) on how to do that.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Hi Maarten, thanks for the response. Below is a sample of my data:

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float CountryNum str48 Country int Year str2 EconomicRegion2019 double(DepressionPrev SuicideRate)
      1 "Afghanistan"    1990 "L" .0408560809156679 10.3185041279549
      1 "Afghanistan"    1991 "L" .0407920823075622 10.3270104500041
      1 "Afghanistan"    1992 "L" .0407048655975331 10.2714111890416
      1 "Afghanistan"    1993 "L" .0406604799497857 10.3761228683411
      1 "Afghanistan"    1994 "L" .0406540039260417 10.5759145441461
      1 "Afghanistan"    1995 "L"  .040652433609251 10.6823495644828
      1 "Afghanistan"    1996 "L"  .040678033606743  10.720222847466
      1 "Afghanistan"    1997 "L" .0407403547944048 10.7918222377962
      1 "Afghanistan"    1998 "L" .0408268864157185 10.8624074437158
      1 "Afghanistan"    1999 "L" .0409067316795364  10.970915166516
      1 "Afghanistan"    2000 "L"   .04094524573839 11.0947432200641
      1 "Afghanistan"    2001 "L" .0409156572981134  11.175178260235
      1 "Afghanistan"    2002 "L" .0408385569503497 11.0544724130193
      1 "Afghanistan"    2003 "L" .0407592711271612 10.9310926684929
      1 "Afghanistan"    2004 "L" .0406903464897289 10.8397902521684
      1 "Afghanistan"    2005 "L" .0406516571182214 10.6556263827148
      1 "Afghanistan"    2006 "L" .0406444092991514 10.5384752685864
      1 "Afghanistan"    2007 "L" .0406317409140969 10.3911287480941
      1 "Afghanistan"    2008 "L" .0406195887185866 10.2191536282447
      1 "Afghanistan"    2009 "L" .0406159595492444  10.036656612642
      1 "Afghanistan"    2010 "L" .0406175837588872 9.87539258237426
      1 "Afghanistan"    2011 "L" .0406322682291403 9.72186925459132
      1 "Afghanistan"    2012 "L" .0406566596950581 9.57065057900413
      1 "Afghanistan"    2013 "L" .0406855615178575 9.44766138671321
      1 "Afghanistan"    2014 "L" .0407188560107943 9.34673059822699
      1 "Afghanistan"    2015 "L" .0407468648129695  9.3191139906738
      1 "Afghanistan"    2016 "L" .0407303005981798 9.25159986184833
      1 "Afghanistan"    2017 "L" .0407133963201374 9.18856839991993
      1 "Afghanistan"    2018 "L" .0407756849206637                .
      1 "Afghanistan"    2019 "L" .0409066133095214                .
      2 "Albania"        1990 "M" .0135389303240527 3.98516989836589
      2 "Albania"        1991 "M" .0135502057140485 4.19900670506314
      2 "Albania"        1992 "M" .0135777845116861 4.09420009962095
      2 "Albania"        1993 "M" .0136186414709952 3.99379570351613
      2 "Albania"        1994 "M" .0136682498678804 3.83212351391277
      2 "Albania"        1995 "M" .0137239670371148 3.99658373439064
      2 "Albania"        1996 "M" .0138052084962864 4.26962291647126
      2 "Albania"        1997 "M" .0138913763134865 4.56311396281924
      2 "Albania"        1998 "M" .0139944659595864 4.75940781317434
      2 "Albania"        1999 "M" .0141579882997326 4.80816867262347
      2 "Albania"        2000 "M" .0142945363954687 4.86701957066737
      2 "Albania"        2001 "M" .0143817686998483 5.05108394895781
      2 "Albania"        2002 "M" .0144704840713434 5.26610402317284
      2 "Albania"        2003 "M" .0145496917720361 5.46462575107308
      2 "Albania"        2004 "M"  .014607189344053 5.63102363876003
      2 "Albania"        2005 "M" .0146309176458602  5.6163774990296
      2 "Albania"        2006 "M" .0146058322370591 5.50065241930541
      2 "Albania"        2007 "M" .0145421548308992 5.32997865056312
      2 "Albania"        2008 "M" .0144648407622318 5.42147558752574
      2 "Albania"        2009 "M"  .014396565240448 5.28660048510971
      2 "Albania"        2010 "M" .0143578318442172 5.25775401253507
      2 "Albania"        2011 "M" .0143473121041298 5.23957186339348
      2 "Albania"        2012 "M" .0143479582908106 5.19961656388038
      2 "Albania"        2013 "M" .0143579667396815 5.19681601742163
      2 "Albania"        2014 "M" .0143704052657081 5.21657018291087
      2 "Albania"        2015 "M" .0143755482159518 5.19108328893683
      2 "Albania"        2016 "M" .0143741629542606 5.15557910659458
      2 "Albania"        2017 "M" .0143870497149837 5.10878060847002
      2 "Albania"        2018 "M" .0144507194229321                .
      2 "Albania"        2019 "M" .0145666629082159                .
      3 "Algeria"        1990 "M" .0337183948574448 4.83886233359688
      3 "Algeria"        1991 "M" .0335498123756564 4.84281793097349
      3 "Algeria"        1992 "M" .0333951355035503 4.86731620221792
      3 "Algeria"        1993 "M" .0332605278855215  4.9140743366917
      3 "Algeria"        1994 "M" .0331522638401438 5.05118197693958
      3 "Algeria"        1995 "M" .0330766954683956 5.09269165288559
      3 "Algeria"        1996 "M" .0330261782493018 5.14083132957216
      3 "Algeria"        1997 "M" .0329815185829691 5.19511371887633
      3 "Algeria"        1998 "M" .0329415748411108 5.19407668778325
      3 "Algeria"        1999 "M" .0328994100389051 5.26244102486573
      3 "Algeria"        2000 "M" .0328549583420267 5.26835867189677
      3 "Algeria"        2001 "M" .0327982445593262 5.26595622642517
      3 "Algeria"        2002 "M" .0327226528671152 5.24978922465377
      3 "Algeria"        2003 "M" .0326365762650973 5.09878634995847
      3 "Algeria"        2004 "M"  .032543715033233 5.03952855448661
      3 "Algeria"        2005 "M" .0324525875369634 4.96704895260906
      3 "Algeria"        2006 "M" .0323197100116501 4.88188892161778
      3 "Algeria"        2007 "M" .0321304928701967 4.79079219172001
      3 "Algeria"        2008 "M"  .031934481771384 4.69123762263069
      3 "Algeria"        2009 "M" .0317789288347278 4.60304134538344
      3 "Algeria"        2010 "M" .0317137677401988 4.50749334350865
      3 "Algeria"        2011 "M" .0317476197172612 4.46207032704655
      3 "Algeria"        2012 "M" .0318349755520022  4.3884416229494
      3 "Algeria"        2013 "M" .0319426742870085 4.34927012045409
      3 "Algeria"        2014 "M" .0320380707995079 4.32945657727614
      3 "Algeria"        2015 "M" .0320894784225569   4.291621910652
      3 "Algeria"        2016 "M" .0320177569054523 4.18781470021409
      3 "Algeria"        2017 "M" .0319652678732525 4.12430646193392
      3 "Algeria"        2018 "M" .0322075321464128                .
      3 "Algeria"        2019 "M" .0327175811419446                .
      4 "American Samoa" 1990 "M" .0139444095860065 6.84665005335045
      4 "American Samoa" 1991 "M" .0138646941594683 6.81114819125232
      4 "American Samoa" 1992 "M" .0137899571839374 6.76453751640861
      4 "American Samoa" 1993 "M" .0137231295873954 6.74624558385127
      4 "American Samoa" 1994 "M" .0136664473648662 6.74661508871285
      4 "American Samoa" 1995 "M" .0136219903946288 6.71902462154722
      4 "American Samoa" 1996 "M" .0135841042212095 6.68802941335749
      4 "American Samoa" 1997 "M" .0135443252803234 6.71325790835888
      4 "American Samoa" 1998 "M" .0135059668887098 6.64327331694032
      4 "American Samoa" 1999 "M" .0134726649713064 6.53326996735081
      end
      The second to last column is the prevalence of depression, and the last column is the suicide rate.

      I hope this helps


      Last edited by Yasmin Pewsey; 22 Apr 2021, 12:41.

      Comment


      • #4
        what variable in your example is "income group"?

        Comment


        • #5
          Looking at the data posted in #3, I believe it also needs the country's population from whom the prevalence or rate was computed. It's because we cannot average the rates in all the "M" economic region; the rates have to be weighted by the population size.

          Comment


          • #6
            Hi Rich,
            The 4th column is the income group. L = low income, M = medium income, H = high income. I don’t currently have the data on population, is there a way I can weight them equally?

            Thanks

            Comment


            • #7
              A plain average is equivalent to equal weighting.

              Comment


              • #8
                Hi Nick,

                Yes, an average is equivalent to equal weighting. Do you know how to code a graph showing how the average prevalence of depression/suicide rate is changing over time by income group, as mentioned in #1?

                Comment


                • #9
                  I should think everyone who has answered knows this. The uncertainty is just exactly what you want. It appears to be something like

                  Code:
                  egen mean = mean(SuicideRate) , by(EconomicRegion2019 Year)
                  
                  separate mean, by(EconomicRegion2019) veryshortlabel
                  
                  line mean? Year ytitle(something sensible)
                  I would be queasy about using means here for the usual reasons, but you'll know what graph fits with the rest of what you've done.
                  Last edited by Nick Cox; 23 Apr 2021, 03:52.

                  Comment


                  • #10
                    Thanks Nick,

                    When I used the code:
                    Code:
                    egen mean = mean(SuicideRate) , by(EconomicRegion2019 Year) 
                    separate mean, by(EconomicRegion2019) 
                    line mean Year
                    It generated this graph:
                    Click image for larger version

Name:	Screenshot 2021-04-23 at 10.44.25.png
Views:	1
Size:	265.9 KB
ID:	1605301


                    I know I didn't exactly copy your code. Stata displayed the error "option veryshortlabels not allowed" for the veryshortlabels command, and when I typed ytitle(XXX) it said "variable XXX not allowed". So I just took these two commands out of the code. That being said, this graph doesn't show what I hoped. I am wanting to display 3 lines, one for low-income, one for middle-income, and one for high-income countries, showing how the suicide rate has changed year on year. Do you know how I can code for this?

                    Thanks

                    Comment


                    • #11
                      Yes. I just fixed one error in my previous. veryshortlabel is an undocumented option, except for https://www.stata-journal.com/sjpdf....iclenum=gr0023 and mentions here which you aren't expected to know about. I wrote separate before it was folded into official Stata. But veryshortlabels is not alllowed.

                      This is closer to what you want

                      Code:
                      separate mean, by(EconomicRegion2019) veryshortlabel  
                      
                      line mean? Year, sort
                      What you did has spurious connections between the means for different groups. You should edit the variable labels. Also, they won't sort in the right order as they will sort H L M so a further guess is that what you really want could be more like

                      Code:
                      line mean1 mean3 mean2 Year, sort 
                      Last edited by Nick Cox; 23 Apr 2021, 04:02.

                      Comment


                      • #12
                        Hi Nick,
                        It works! I used the code:
                        Code:
                        egen meanS = mean(SuicideRate) , by(EconomicRegion2019 Year)
                        separate meanS, by(EconomicRegion2019)
                        line meanS1 meanS2 meanS3 Year, sort
                        And it produced this wonderful graph:
                        Click image for larger version

Name:	Screenshot 2021-04-23 at 11.35.37.png
Views:	1
Size:	153.3 KB
ID:	1605308


                        I played around with the titles etc in the graph editor. Thank you so much, you've helped me a lot!

                        Comment


                        • #13
                          Direct labelling is a better idea. This self-contained example shows the principle.

                          Code:
                          clear
                          set obs 5
                          gen year = 2000 + _n 
                          gen high = 12
                          gen medium = 10
                          gen low = 8
                          set scheme s1color 
                          
                          line high medium low year, lc(orange_red blue black) xsc(r(2001 2005.5)) legend(off) || scatteri 12 2005 "high", mlabcolor(orange_red) ms(none) mlabsize(medsmall)  || scatteri 10 2005 "medium", mlabcolor(blue) ms(none) mlabsize(medsmall) legend(off) || scatteri 8 2005 "low", mlabcolor(black) ms(none) mlabsize(medsmall)
                          Click image for larger version

Name:	directlabelling.png
Views:	1
Size:	19.3 KB
ID:	1605312

                          Comment


                          • #14
                            I'd suggest renaming the title to "Mean country-level suicide rate (per 100,000, unweighted) over time" and y axis to "Mean country-level suicide rate (per 100,000, unweighted)". Let's say country A (100 pop) has 90% prevalence (90/100) and country (5000) has 20% prevalence (1000/5000). If we just average their rate it's 55%. But in reality the rate is only 1090/5100 = 21.4%. Calling it "mean rate" is very misleading. To avoid perpetuating any misunderstanding, it'd be better to state that up front.

                            Comment


                            • #15
                              Hi Ken,
                              I will rename the title, thank you for the suggestion

                              Comment

                              Working...
                              X