Announcement

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

  • lpolyci: restricting polynomial to have positive values

    Dear all

    I have a twoway graph with a scatter plot and a second order fitted polynomial. I tried restricting the scale and label of the y-axis to begin from 0 but because the fitted polynomial has negative values, it did not work. Is there a way to either impose that the polynomial must have positive values or to avoid any negative values in the y-axis to be plotted?

    Code:
    twoway lpolyci percap_pri prop60plus if year==2015, degree(2) nofit color(%40) || ///
    scatter percap_pri1 prop60plus1 if year==2015, ///
    msymbol(p) mla(location) mlabsiz(1.8) mcolor(blue*1.3) mlabcol(blue*1.3) || ///
    scatter percap_pri2 prop60plus2 if year==2015, ///
    msymbol(o) mla(location) mlabsiz(1.8) mcolor(red*1.2) mlabcol(red*1.2) ///
    ytitle("private health spending per capita") xtitle("% population > 60 years old") ///
    ylab(0(1000)5000, grid) ysc(range(0 5000)) ylab(,labsize(vsmall) format(%15.0fc)) ///
    xlab(0(5)35, grid) xsc(range(0 35)) xlab(,labsize(vsmall)) ///
    graphregion(color(white)) legend(off) name(graf_disp_pri, replace)
    Click image for larger version

Name:	graf_disp_pri.png
Views:	1
Size:	71.7 KB
ID:	1446898

  • #2
    I would strongly recommend thinking about health spending on logarithmic scale, because of this graph and on general grounds.

    Comment


    • #3
      Ok Nick, thanks. I don“t know if it makes sense once I am not looking at private health spending for the same country over time. Instead I am looking at private health spending across different countries for the same year. Also, the health spending here is PPP adjusted. Indeed, the US is an outlier in terms of private health spending and this should be shown in the graph.

      Would you know how I could restrict the polynomial to have positive values?

      Comment


      • #4
        You could use a flexible model that uses a log link function for this purpose. In Stata one possible candidate for the flexible part is the fp prefix, and for the log link function poisson (for the latter point see https://blog.stata.com/2011/08/22/us...tell-a-friend/

        Code:
        clear
        input str3 countrycode double(percap_pri prop65plus)
        "AFG"    43.9159313 2.45951067860634
        "AGO"    56.1209257 2.28338172154969
        "ALB"  176.04434604 12.1369841908398
        "ARE"  468.25980495 .988196607887648
        "ARG"  246.05027941 10.8089582230873
        "ARM"  214.91710074 10.8608777036838
        "ATG"   214.5762827 6.52642225031606
        "AUS" 1840.21854241 14.6756409930909
        "AUT" 1299.36419237 18.6564572662344
        "AZE"  340.86491905 5.68903648877903
        "BDI"    4.83048475 2.50890890324198
        "BEL"  896.54146223 17.9809434947943
        "BEN"   17.14586677 3.22829102243749
        "BFA"    16.0938175 2.42327736468665
        "BGD"   20.87201858 5.00836048221464
        "BGR"  313.04160327 19.7183385268504
        "BHR"  416.36554229 2.29505154531176
        "BHS"  931.52505829 7.99593896940882
        "BIH"  143.83821608 15.2835584500513
        "BLR"  155.44561658 14.2214253023057
        "BLZ"   82.54334734 3.75354711766479
        "BOL"   58.62621879 6.33912062865177
        "BRA"  562.80733063 7.68207792003269
        "BRB"  607.99970039 13.7593732907529
        "BRN"   58.31295553 3.89187377339059
        "BTN"   18.39092488 4.58137570062644
        "BWA"  139.48914527 3.65221737981613
        "CAF"    8.31945741 3.68096501920542
        "CAN" 1329.18011964 15.7074223400892
        "CHE" 2922.06503619 17.8013492467279
        "CHL"  447.17757707 10.1338791327118
        "CHN"  159.42170121 9.30929170209179
        "CIV"   50.73436291 2.88710618760083
        "CMR"    56.3116161 3.17587252175189
        "COD"    8.90859139 3.01885738019388
        "COG"   28.06454972  3.3585425553689
        "COL"  139.56388689 6.76051225488765
        "COM"   53.65066901 2.89194545586231
        "CPV"   49.40708588 4.59371206811071
        "CRI"  225.67492102 8.60043194274394
        "CYP" 1023.69878143 12.5330098090009
        "CZE"  261.93704826 17.4872996490267
        "DEU"  832.70808725 20.9819577109538
        "DJI"   17.24413698 4.02767484794401
        "DNK" 1027.04775249 18.5702325282481
        "DOM"  194.16002393 6.51112009751443
        "DZA"  100.06658856 5.73198695799561
        "ECU"  263.16691351 6.53834293564681
        "EGY"   102.8741477  5.0157241003372
        "ESP"    805.695869 18.5211793165389
        "EST"  301.47845067 18.5448728305416
        "ETH"   13.20489684 3.45030328313024
        "FIN" 1051.98375267 19.6858371963235
        "FJI"    63.9002018 5.63938379283951
        "FRA" 1013.77506016 18.4856162358131
        "FSM"   10.79575061  4.2003557179253
        "GAB"   96.03198153 4.60054389983969
        "GBR"  898.47262732 17.8568768773739
        "GEO"  243.99636544  14.486670243511
        "GHA"   38.42033795 3.41556920979656
        "GIN"   15.53515081 3.05810617737871
        "GMB"    7.70473521 2.34882566537981
        "GNB"   16.87646882 2.84671422876162
        "GNQ"   256.2248316 2.92715578914562
        "GRC"  698.60036494 19.6121148441604
        "GRD"  259.80054435 7.14742384355021
        "GTM"  142.11611275 4.43530243458764
        "GUY"   81.07366302 4.92865404843901
        "HND"   94.78559632  4.3121203975473
        "HRV"  223.64622416 18.5706370332303
        "HTI"   24.00734432  4.5793762779658
        "HUN"  331.04503482 17.1254522545088
        "IDN"   71.63811421 5.02918193639697
        "IND"   43.19964865 5.50406936289318
        "IRL" 1693.39670222 12.7856302574265
        "IRN"  189.91182388 4.95135943266802
        "IRQ"  115.95493661 3.07197492549866
        "ISL"  873.93742727 13.3219062348725
        "ITA"  776.92779593 21.9854797969203
        "JAM"  116.92569542 9.10660647282909
        "JOR"   89.37411683 3.72767162362166
        "JPN"  651.08280799 25.3523967116436
        "KAZ"  173.34753283 6.75156633669719
        "KEN"   33.92526017 2.54230541508009
        "KGZ"    53.7296134 4.28047752852769
        "KHM"   42.84058359 4.01595464281809
        "KIR"     5.2742801 3.65387749189737
        "KOR"  873.34297435 12.4763265507022
        "KWT"  193.24372039 2.01586273447104
        "LAO"     24.793048 3.83437922011095
        "LBN"  311.12686345 8.13994805541541
        "LBR"   15.71013903 3.03037963786034
        "LCA"   257.2951367 9.24209702926522
        "LKA"   45.90725753 8.89878199519733
        "LSO"   17.45558407 4.43310956130274
        "LTU"  337.62800992 18.4042654479672
        "LUX" 1273.93234393 13.9640060684934
        "LVA"  491.63955087 19.0689565379131
        "MAR"   99.73459411 6.27422301747516
        "MDA"   90.58042165 9.87857557570273
        "MDG"    6.88004127 2.81425434661361
        "MDV"  217.27962235 4.15777703204188
        "MEX"  286.06403162 6.32456191193802
        "MKD"  121.94534966 12.2650596030315
        "MLI"   22.91494627 2.57213913278468
        "MLT"  959.07283204 17.8052964259699
        "MMR"   46.26065002 5.18126409771848
        "MNE"  143.15055368 13.5927248858484
        "MNG"   64.81957318 3.85290721694616
        "MOZ"    2.37107941 3.13045730432566
        "MRT"   29.41691995 3.09496742061852
        "MUS"  284.05711863  9.4152251914742
        "MWI"    4.12555165 3.00359051975301
        "MYS"  201.60328078 5.66347438536904
        "NAM"  132.73321588 3.46158907326554
        "NER"    14.7271833 2.53224072693131
        "NGA"   79.83193143 2.75040643372986
        "NIC"   58.64678401 4.96009559033701
        "NLD" 1097.28607253 17.4452596061093
        "NOR"  1341.4013347 16.0463248235369
        "NPL"   29.32183405 5.31433531918187
        "OMN"   73.88280712 2.34215492593271
        "PAK"    25.1291358 4.48298668724964
        "PAN"  328.51891118 7.37333586749543
        "PER"  124.83723576 6.67637092192211
        "PHL"   84.28748288 4.47728402186049
        "PNG"    4.21146046 3.58951414976047
        "POL"  262.11535201 15.0989395989769
        "PRT"  673.90990043 20.3056335262695
        "PRY"  164.43596309 5.85822325970945
        "QAT"  278.98091382 1.05099394841433
        "ROU"  105.71214016 16.6601461111788
        "RUS"  283.65272371 13.3259901000671
        "RWA"   19.30491384 2.75709261506711
        "SAU"  331.86986797 2.98948016621133
        "SDN"   78.71191345 3.41799240461443
        "SEN"    23.9059743 3.00814423869033
        "SGP" 1089.47551526 11.0565012255104
        "SLB"     5.6435387  3.4244766326559
        "SLE"   56.23186668 2.50628534846356
        "SLV"   92.67512886 7.77093317841574
        "SRB"   250.7455574 15.8669408755174
        "SSD"   17.16931871 3.46472122772661
        "STP"   22.50518475 3.10666820030743
        "SUR"  267.55948346 6.57677651078244
        "SVK"   254.6004557 13.6575320352648
        "SVN"  607.09287362 17.6468543034365
        "SWE" 1102.56195387 19.3884828083872
        "SWZ"   50.27843118 3.10216145972078
        "SYC"   13.37582363 7.94175048791473
        "TCD"   26.83461195 2.47281427572756
        "TGO"   24.59987178 2.77806558798934
        "THA"   48.67753673 10.1753996812361
        "TJK"   46.01387859 3.30190625207393
        "TKM"  318.48976806 4.03489344871549
        "TLS"    7.28058878 3.39986180898307
        "TON"    32.9212766 5.87340001134408
        "TTO"  485.02420203 9.16424078972723
        "TUN"  121.64359456 7.50211685164666
        "TUR"  118.06630949 7.64580810635479
        "TZA"   10.19855546 3.11011596487396
        "UGA"   25.10251073  2.1882332134312
        "UKR"   94.46969559  15.794560780632
        "URY"  417.54206169 14.3323704374791
        "USA" 4531.12015453 14.2673275853172
        "UZB"   58.36451749 4.21339375463653
        "VCT"   68.36557747 7.16826540596395
        "VEN"  290.34273156 6.09125178953815
        "VNM"   54.31550889 6.62619226566905
        "VUT"   12.58887605 4.10817075526367
        "WSM"   30.66949424 5.26184408965625
        "YEM"    61.7530728  2.8306970342936
        "ZAF"  223.00172233 4.98204872201873
        "ZMB"   36.74608803 2.51764070537471
        "ZWE"   36.69959439 2.85273339854364
        end
        
        
        
        fp <prop65plus> : poisson percap_pri <prop65plus>, vce(robust)
        predict xb, xb
        predict se, stdp
        
        gen yhat = exp( xb )
        gen lb = exp( xb - invnormal(0.975)*se )
        gen ub = exp( xb + invnormal(0.975)*se )
        
        set scheme s1mono
        twoway rarea lb ub prop65plus, sort astyle(ci)       || ///
               line yhat prop65plus, sort                       ///
                   lpattern(solid)  lcolor(gs10)             || ///
               scatter percap_pri prop65plus                    ///
                   if countrycode != "BRA",                     ///
                   yscale(log)                                  ///
                   ylab(5 10 50 100 500 1000 5000,              ///
                       format(%9.0gc) angle(0) grid)            ///
                   xlab(,grid)                                  ///
                   msymbol(i) mlabel(countrycode) mlabpos(0) || ///
               scatter percap_pri prop65plus                    ///
                   if countrycode == "BRA",                     ///
                   msymbol(i) mlabel(countrycode) mlabpos(0)    ///
                   mlabcol(red) legend(off)                     ///
                   ytitle("private health spending per capita") ///
                   xtitle("% population > 65 years old")
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          It's not the polynomial you need to worry about given your approach. It won't go beyond the data (space for minor qualifications). The confidence intervals are your problem and my view remains that the problem behind that is working on an inappropriate scale.

          This being cross-sectional data rather than time series data has, so far as I can see, no bearing on the issue.

          Comment

          Working...
          X