Announcement

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

  • Draw a time grapg with projections in another line style

    Hello Stata users;

    I'm using Stata version 13.1 for this, I have this data at hand:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year double World_Population float World_Population_Growth_Rate
    1700  595456896 .
    1710  617975872 .
    1720  648184768 .
    1730  670899968 .
    1740  702227776 .
    1750  753279296 .
    1760  788254976 .
    1770  827951488 .
    1780  900945152 .
    1790  942261696 .
    1800  983104755 .
    1801  986464967 .
    1802  989864750 .
    1803  993304404 .
    1804  996784263 .
    1805 1000304675 .
    1806 1003866016 .
    1807 1007468698 .
    1808 1011113144 .
    1809 1014799822 .
    1810 1020150076 .
    1811 1025557675 .
    1812 1031616616 .
    1813 1038342722 .
    1814 1045238421 .
    1815 1052307852 .
    1816 1059555372 .
    1817 1066985519 .
    1818 1074603043 .
    1819 1082114553 .
    1820 1089507052 .
    1821 1096534977 .
    1822 1103392066 .
    1823 1110594705 .
    1824 1117897019 .
    1825 1125304048 .
    1826 1132861806 .
    1827 1140524282 .
    1828 1148292956 .
    1829 1155618460 .
    1830 1162497339 .
    1831 1168886301 .
    1832 1174792985 .
    1833 1180213555 .
    1834 1185694036 .
    1835 1191237685 .
    1836 1196838401 .
    1837 1202503348 .
    1838 1208233715 .
    1839 1213934891 .
    1840 1219617217 .
    1841 1225283810 .
    1842 1230929323 .
    1843 1236555463 .
    1844 1242258939 .
    1845 1248042343 .
    1846 1253907423 .
    1847 1259855932 .
    1848 1265889730 .
    1849 1271136843 .
    1850 1275602897 .
    1851 1278768180 .
    1852 1281158448 .
    1853 1282781891 .
    1854 1284514999 .
    1855 1286359120 .
    1856 1288315736 .
    1857 1290386388 .
    1858 1292572700 .
    1859 1295121860 .
    1860 1298027373 .
    1861 1301279942 .
    1862 1304883100 .
    1863 1308825538 .
    1864 1312850777 .
    1865 1316952210 .
    1866 1321129252 .
    1867 1325389634 .
    1868 1329732282 .
    1869 1334654211 .
    1870 1340168478 .
    1871 1346202715 .
    1872 1352896118 .
    1873 1360163018 .
    1874 1367501771 .
    1875 1374940414 .
    1876 1382459121 .
    1877 1390028839 .
    1878 1397666358 .
    1879 1405838237 .
    1880 1414583216 .
    1881 1423919001 .
    1882 1433850986 .
    1883 1444371648 .
    1884 1455021634 .
    1885 1465857041 .
    1886 1476798447 .
    1887 1487893376 .
    1888 1499115427 .
    1889 1510109709 .
    end
    format %ty year
    As you can see, it is the yearly evolution of the world population (the size) and the world population growth rate (in %, the values are available starting from 1950 for this variable) from 1700 to 2023, with projections for the two variables from 2024 to 2024.
    The idea is to draw the two variable lines on the same graph, with two Y-axes, and with the projected lines (starting from 2024) for the two variables in dashes or short lines (in order to show that those are projections. It would also be helpfull if it's possible to put some values of the extrem points (like, the maximum value that the growth rate reached, the population size for some selected years, ...) on the lines.

    Can I get some help with this?

    With many thanks!

  • #2
    Projections from 2024 to 2024? Presumably longer?

    Comment


    • #3
      The entire data, and especially the projection was not included in your example. So I created my own data. Here is an example of how to show the estimates and the projections in different colors and line patterns.

      Code:
      clear
      input long year double population
      1700              652.5
      1750  751.4285888671875
      1800  920.7999877929688
      1850               1218
      1875               1325
      1900  1647.142822265625
      1920               1813
      1925               2000
      1930               1987
      1940               2213
      1950 2471.4240019999997
      1950               2495
      1951        2514.761693
      1952        2559.092377
      1953 2609.0803020000003
      1954 2659.1321690000004
      1955        2712.657551
      1956        2767.770034
      1957        2823.049954
      1958         2882.18672
      1959        2940.312621
      1960        2991.588081
      1961        3039.353708
      1962        3090.385641
      1963        3156.362989
      1964 3229.2526660000003
      1965 3299.7220129999996
      1966        3369.345394
      1967        3438.736856
      1968        3508.088904
      1969 3582.2855980000004
      1970 3656.6975610000004
      1971 3732.6700260000002
      1972        3807.025705
      1973        3882.809654
      1974 3958.8004300000002
      1975        4034.031762
      1976        4107.438793
      1977        4181.053962
      1978         4254.67363
      1979        4329.521373
      1980        4407.557683
      1981         4487.65479
      1982        4569.899823
      1983        4655.447019
      1984  4739.208127999999
      1985 4825.1429100000005
      1986 4912.7440209999995
      1987  5003.401655000001
      1988 5096.0911399999995
      1989        5187.893944
      1990         5280.96952
      1991          5374.6367
      1992        5462.835083
      1993        5549.144549
      1994 5633.9450449999995
      1995        5717.157466
      1996        5800.600498
      1997        5883.510969
      1998 5966.0646639999995
      1999  6048.068714999999
      2000        6129.943964
      2001        6213.462023
      2002  6296.410895999999
      2003  6379.049787999999
      2004        6461.673479
      2005 6545.0820650000005
      2006        6628.858198
      2007  6714.045832999999
      2008  6800.571730000001
      2009        6888.343594
      2010        6977.189237
      2011 7066.2750590000005
      2012        7155.572472
      2013        7246.832497
      2014        7336.754673
      2015        7426.477815
      2016 7514.5059280000005
      2017        7602.603123
      2018        7688.632785
      2019  7771.172775999999
      2020        7851.414621
      2021  7922.587963000001
      2022         7986.30882
      2023        8056.505564
      2024        8126.964296
      2025        8196.980849
      2026  8266.245291000001
      2027          8335.1115
      2028        8403.077189
      2029  8470.160584000001
      2030        8536.410062
      2031  8601.839759999999
      2032  8666.398906999999
      2033        8730.060717
      2034  8792.837445000001
      2035        8854.732372
      2036         8915.68799
      2037        8975.685239
      2038        9034.620009
      2039        9092.525843
      2040        9149.330917
      2041        9205.049488
      2042  9259.513662000001
      2043        9312.707079
      2044        9364.615549
      2045        9415.131838
      2046        9464.147498
      2047  9511.631710000001
      2048  9557.460244999998
      2049        9601.611841
      2050        9644.036216
      2051        9684.720958
      2052        9723.663649
      2053        9760.865381
      2054  9796.363846999999
      2055        9830.139471
      2056         9862.33567
      2057        9893.025114
      2058        9922.249272
      2059  9950.079485999999
      2060        9976.594679
      2061       10001.869905
      2062       10025.962521
      2063       10048.970678
      2064 10070.929392000002
      2065       10091.876081
      2066       10111.823041
      2067       10130.811174
      2068       10148.805547
      2069 10165.798334000001
      2070 10181.765935000001
      2071 10196.717982999999
      2072       10210.645154
      2073       10223.465184
      2074       10235.190464
      2075       10245.779647
      2076       10255.213216
      2077       10263.489648
      2078       10270.600397
      2079 10276.512247999999
      2080       10281.262698
      2081       10284.893359
      2082       10287.430111
      2083       10288.979989
      2084       10289.514658
      2085        10289.11583
      2086 10287.797368000001
      2087       10285.619351
      2088       10282.603396
      2089       10278.805749
      2090 10274.230810000001
      2091       10268.899331
      2092       10262.824096
      2093       10255.992655
      2094       10248.376862
      2095       10239.994812
      2096       10230.812389
      2097 10220.889357999999
      2098       10210.209263
      2099       10198.770461
      2100        10186.60767
      end
      
      twoway line population year if year <=2023,        ///
             lcolor(green) ||                            ///
             line population year if year > 2023,        ///
             ytitle("world population (millions)")       ///
             ylab(,format("%9.0fc"))                     ///
             legend(order(1 "estimated" 2 "projection")) ///
             lpattern(dash) lcolor(pink)
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Nick Cox Hello... I meant projections from 2024 to 2100, sorry, that was just a mistyping from my part.

        Comment


        • #5
          Maarten Buis Thanks for the suggestion, it worked. The thing is that the command "dataex" that I've applied stopped just before the start of the values of the variable "Growth Rate", and it didn't also cover the projected variables. It's just a matter of options for the command "dataex" I guess.

          Comment


          • #6
            Indeed. See #3 in your previous thread https://www.statalist.org/forums/for...s-of-the-years for advice to reach for the count() option of dataex. when you need it.

            More general advice is to check the help of any command when it doesn't do what you want to see what extra functionality there might be.

            Comment

            Working...
            X