Announcement

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

  • Scatterplot (nonlinear relationship)

    Hi!

    I got the following scatterplot (below) that clearly illustrates a nonlinear relationship between the coefficient and GDP per capita. I want to build a curve that best fits this relationship (as per the other picture). However, I am not finding the right way to do it. I know the plot is not a twoway line but also I think I am not properly using curvefit. Is there a way I can use my data to get something on the lines of the figure? Many Thanks!

    Code:
     * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(country year) double(GdpCod GdpCud MvaCod MvaCud Pop) float(Mva_output GDPpercapita MVA_capita region coeff_diversi) byte _merge float predict
     4 1990           .  3559511736 1839648920  683514541 12412310   .1920248         . 148.21165 6         0 3         .
     4 1991  7907838197  3402654940 1748969501  680342026 13299020  .19994447  594.6181 131.51115 6         0 3 .51096517
     4 1998  5930467283  2935139404  665837681  298073135 19737770  .10155331  300.4629 33.734188 6         0 3 .51036495
     4 1999  5646938964  2157197316  797533419  287999806 20170850  .13350648  279.9554  39.53891 6         0 3  .5103231
     4 2001  5043434615  3598470576 1044943336  675408326 21606990  .18769316  233.4168  48.36135 6         0 3  .5102281
     4 2002  7492885091  4141523943 1432080334  720338527 22600770   .1739308  331.5323  63.36423 6 .28729656 3  .5104283
     4 2003  8677278663  4729042179 1451437991  691580599 23680870  .14624116  366.4257  61.29158 6  .6395056 3 .51049954
     4 2004  8925480897  5388482107 1385657920  746469467 24726690  .13853057 360.96545  56.03896 6  .6514391 3  .5104884
     4 2005  9595643585  6220574147 1315397188  772808251 25654270  .12423423  374.0369  51.27401 6   .625147 3  .5105151
     4 2006 10417346606  7104711445 1245626269  790852547 26433060  .11131382  394.1029   47.1238 6   .623127 3 .51055604
     4 2007 12776134707  9412161765 1191360243 1036748730 27100540   .1101499  471.4347  43.96076 6  .6246927 3  .5107138
     4 2008 12634956169 10236901594 1123828277 1075453417 27722280  .10505654   455.769  40.53881 6  .6405458 3 .51068187
     4 2009 14008170592 11595133469 1079062230  902301144 28394810  .07781723  493.3356 38.002094 6  .6217199 3  .5107585
     4 2010 14743563274 14698889678 1031099173  957689032 29185510  .06515384  505.1672 35.329147 6   .645614 3 .51078266
     4 2011 15740595785 17350694945  976531082 1097137284 30117410  .06323305  522.6411 32.424137 6  .6468787 3  .5108183
     4 2012 17267933277 19136499341  953218483 1060751259 31161380  .05543079  554.1453  30.58974 6  .6410681 3  .5108826
     4 2013 18416377364 19621802455  896922510  916920660 32269590  .04672968  570.7038 27.794666 6  .6464872 3  .5109164
     4 2014 18982386671 19550702567  809259473  837661844 33370800  .04284561  568.8322 24.250526 6  .4097601 3  .5109126
     4 2015 18713048410 18713048410  744252334  744252334 34413600  .03977184   543.769  21.62669 6 .54373574 3 .51086146
     4 2016 19021914408 18037637165  689672188  657075292 35383030 .036428012  537.5999  19.49161 6         0 3  .5108488
     4 2017 19526929963 18623026651  666428610  578753034 36296110  .03107728  537.9896 18.360882 6         0 3 .51084965
     4 2018 19835598333 17986967500 1122829139  931880027 37171920  .05180862  533.6178  30.20638 6  .5270137 3  .5108407
     4 2019 20634468349 17876546427 1015595580  851545152 38041760  .04763477 542.41626  26.69686 6   .524656 3 .51085865
     8 1990  5274245821  2145774521  560114888  428496505  3286070  .19969316 1605.0315  170.4513 4         0 3  .5130271
     8 1993  3861338953  1700439874  154157764  125767201  3195200  .07396157 1208.4812  48.24667 4  .6040229 3  .5122178
     8 1994  4181940822  1880950821  145443045  125719469  3146520  .06683826 1329.0686  46.22346 4  .6583417 3  .5124639
     8 1995  4739072837  2392764887  160719942  155988530  3112920  .06519175 1522.3883  51.62996 4  .5497537 3  .5128584
     8 1996  5170410969  3199642024  188124618  155433263  3098700  .04857833 1668.5742  60.71082 4  .5354103 3  .5131567
     8 1997  4610049287  2224654241  146057340  101965734  3099750  .04583442 1487.2327  47.11907 4  .4544601 3  .5127867
     8 1998  5017086636  2554868837  206519276  120689616  3110700  .04723907  1612.848  66.38997 4  .7088562 3   .513043
     8 1999  5663824817  3221670165  233283743  146019874  3122700  .04532428  1813.759  74.70578 4  .7213641 3   .513453
     8 2000  6057247912  3487586302  249474241  150589639  3129250  .04317876 1935.6868  79.72334 4  .7377325 3  .5137018
     8 2001  6559593147  3926887597  263837307  160961687  3129700  .04098963 2095.9175  84.30115 4  .7439562 3  .5140287
     8 2002  6857173576  4355865889  274862476  177133979  3126180  .04066562 2193.4673  87.92279 4  .7135162 3  .5142278
     8 2003  7236281323  5561459461  327911172  229365194  3118020  .04124191 2320.7937 105.16647 4  .6891021 3  .5144876
     8 2004  7635347831  7177030365  347648294  299825869  3104890  .04177576  2459.136 111.96799 4  .6965503 3  .5147699
     8 2005  8057313206  8052079314  395915701  356374257  3086810  .04425866 2610.2395 128.26047 4  .6537802 3  .5150783
     8 2006  8532902873  8896076004  447491283  436350501  3063020  .04904977  2785.781  146.0948 4  .6482455 3  .5154365
     8 2007  9043447373 10677322220  504112398  565560820  3033990  .05296841  2980.711 166.15494 4  .6657663 3  .5158343
     8 2008  9721714044 12881352058  478755671  643779238  3002680  .04997762  3237.679  159.4428 4  .6531296 3  .5163586
     8 2009 10047807410 12044210390  492614700  626006894  2973040  .05197575  3379.641 165.69394 4  .6646512 3 .51664835
     8 2010 10420269257 11926948284  549640334  650271788  2948030  .05452122  3534.655 186.44327 4   .667496 3  .5169647
     8 2011 10685510487 12890873323  607197439  729866711  2928600  .05661887  3648.675  207.3337 4   .674406 3  .5171973
     8 2012 10836949164 12319779604  512126076  568487378  2914090  .04614428  3718.811 175.74133 4  .6607661 3  .5173404
     8 2013 10945534087 12776280738  562552082  646455586  2903790   .0505981  3769.396  193.7303 4  .6591358 3 .51744366
     8 2014 11139761173 13228240079  615282097  704512442  2896310  .05325821  3846.191 212.43655 4   .664556 3 .51760036
     8 2015 11386924853 11386924853  645808390  645808390  2890520  .05671491 3939.4036  223.4229 4  .7497118 3 .51779056
     8 2016 11764400523 11861356451  675135674  674249719  2886430  .05684423 4075.7615  233.8999 4  .7355759 3 .51806885
     8 2017 12211706325 13019729856  759064475  801776692  2884170  .06158167 4234.0454 263.18298 4  .7344699 3 .51839185
     8 2018 12708881696 15147025232  806677570  931221479  2882740  .06147883  4408.612 279.83014 4  .7342588 3 .51874804
     8 2019 12990264363 15278072762  849713046  959848383  2880910 .062825225 4509.0835 294.94604 4  .7342588 3  .5189531
    12 1990 80470577790 61751375957 4832504583 7065837057 25758870  .11442396  3123.995 187.60545 5 .56680983 3 .51612663
    12 1991 79504930386 46565003199 4798677031 5095171687 26400470  .10942062  3011.497 181.76483 5 .55460024 3  .5158971
    12 1992 80936020962 49105553595 4529951212 5388304531 27028330  .10972902 2994.4885  167.6001 5  .5333213 3  .5158624
    12 1993 79236363907 50846930343 4471061816 5187863527 27635520  .10202904  2867.193 161.78677 5 .52828693 3 .51560265
    12 1994 78523239367 42330711146 4274335141 4270757455 28213780  .10089029  2783.152 151.49814 5 .51635313 3  .5154311
    12 1995 81507118372 41971488420 4214494569 3697157510 28757790  .08808736  2834.262  146.5514 5  .4850963 3  .5155354
    12 1996 84848908978 46836290499 3847833435 3460092904 29266420  .07387632   2899.19 131.47606 5   .477547 3  .5156679
    12 1997 85782246924 48068457028 3701615771 3368896781 29742980  .07008539 2884.1174 124.45342 5         0 3 .51563716
    12 1998 90157144614 48079007974 4012551551 3798146618 30192750  .07899802  2986.053 132.89784 5         0 3  .5158452
    12 1999 93042174640 48531031757 4076752399 3505527079 30623410  .07223269 3038.2695 133.12535 5         0 3 .51595175
    12 2000 96577777276 54666896857 4139114423 3276999541 31042240  .05994486  3111.173 133.33813 5         0 3 .51610047
    12 2001 99475110594 55056733057 4313240349 3432252902 31451510  .06234029  3162.809 137.13937 5         0 3 .51620585
    12 2002   1.050e+11 56819210891 4542512513 3452766594 31855110  .06076759 3296.1746 142.59918 5         0 3   .516478
    12 2003   1.130e+11 67863851626 4617642220 3720883688 32264160  .05482865  3502.338 143.11986 5         0 3  .5168987
    12 2004   1.170e+11 85332517817 4728606728 4368154143 32692150   .0511898  3578.841 144.64043 5         0 3  .5170548
    12 2005   1.240e+11   1.030e+11 4816015354 4601340228 33149720   .0446732  3740.605 145.28073 5         0 3  .5173849
    12 2006   1.260e+11   1.170e+11 4955137069 4932646838 33641010  .04215937 3745.4285 147.29454 5         0 3  .5173948
    12 2007   1.310e+11   1.350e+11 5088703238 5505289469 34166980  .04077992  3834.111  148.9363 5   .609933 3 .51757574
    12 2008   1.340e+11   1.710e+11 5392578565 6330887377 34730600 .037022732  3858.269  155.2688 5  .6108037 3 .51762503
    12 2009   1.360e+11   1.370e+11 5895044737 6420143156 35333880  .04686236  3848.997  166.8383 5  .3561771 3  .5176061
    12 2010   1.410e+11   1.610e+11 6052354606 6729456789 35977450  .04179787 3919.1216 168.22633 5 .46071514 3  .5177492
    12 2011   1.450e+11   2.000e+11 6288483502 7321936163 36661440  .03660968  3955.109 171.52855 5   .273728 3  .5178226
    12 2012   1.500e+11   2.090e+11 6550986139 7534709160 37383900  .03605124  4012.422  175.2355 5 .28442323 3 .51793957
    12 2013   1.540e+11   2.100e+11 6802273837 7776085063 38140140 .037028976  4037.741 178.34947 5   .300954 3 .51799124
    12 2014   1.600e+11   2.140e+11 7016456728 8340052419 38923690  .03897221 4110.6074 180.26186 5 .31376415 3 .51813996
    12 2015   1.660e+11   1.660e+11 7336274552 7336274552 39728020  .04419443  4178.411 184.66248 5  .3705145 3  .5182783
    12 2016   1.710e+11   1.600e+11 7600979295 7056637058 40551400  .04410398 4216.8706  187.4406 5  .3705145 3  .5183568
    12 2017   1.740e+11   1.700e+11 7934997210 7346831009 41389170  .04321665 4203.9985 191.71675 5  .3705145 3  .5183305
    12 2018   1.760e+11   1.750e+11 8216694964 7436073462 42228420  .04249185  4167.809  194.5774 5         0 3 .51825666
    12 2019   1.770e+11   1.710e+11 8519570680 7575810999 43053050  .04430299  4111.207  197.8854 5         0 3 .51814115
    24 1991 35792474873 16189237424 1981457609 1016364681 12248900  .06278027  2922.097 161.76617 3         0 3 .51571465
    24 1992 33702809709 18586675505 1539592564  735830295 12657360  .03958913 2662.7046 121.63615 3         0 3 .51518536
    24 1993 25619724169 13467953136 1450296191  761606416 13075040  .05654953 1959.4375 110.92097 3         0 3 .51375026
    24 1995 29857295202  6642229111 1414743628  265031328 13945210  .03990096  2141.043 101.45015 3         0 3  .5141208
    24 1996 33901277662  8725773846 1451526961  300668715 14400720 .034457542 2354.1377 100.79544 3         0 3  .5145557
    24 1997 36367350628 10226790656 1586518972  449465122 14871570  .04394977  2445.428 106.68134 3         0 3 .51474196
    24 1998 38073396300  8617787793 1664258399  539454645 15359600  .06259781  2478.801 108.35298 3         0 3  .5148101
    24 1999 38903963532  8227190091 1782420748  264960469 15866870 .032205462  2451.899   112.336 3         0 3  .5147552
    24 2000 40092333430 12207354573 1941056194  352772925 16395480  .02889839 2445.3284 118.38972 3         0 3  .5147418
    24 2001 41351232699 11948601236 2090682673  462762726 16945750  .03872945 2440.2126 123.37505 3         0 3 .51473135
    24 2002 47359566810 15285592487 2272463879  559731748 17519420 .036618255  2703.261 129.71114 3         0 3  .5152681
    24 2003 48775545863 17812704626 2352193499  712475148 18121480  .03999814 2691.5874  129.8014 3         0 3  .5152443
    24 2004 54117975511 23552045850 2751454295 1102692818 18758140  .04681941 2885.0396 146.68056 3         0 3 .51563907
    24 2005 62251473449 36970878079 2984452262 1446628304 19433600  .03912886  3203.291 153.57176 3         0 3 .51628846
    24 2006 69502497165 52381025105 4364285817 2209968430 20149910  .04219025  3449.271 216.59084 3         0 3  .5167904
    24 2007 79239331721 65266415707 4640343290 3466475980 20905360  .05311271 3790.3835 221.96907 3         0 3  .5174865
    24 2008 88085965989 88538664888 4762614267 3382548902 21695640   .0382042  4060.077 219.51942 3         0 3 .51803684
    24 2009 88842229341 70307193221 4946579182 4109629970 22514280  .05845248  3946.039 219.70853 3         0 3 .51780415
    24 2010 93159263074 83799478930 5444855344 4194167642 23356250  .05005004 3988.6226   233.122 3         0 3 .51789105
    end
    label values _merge _merge
    label def _merge 3 "matched (3)", modify
    Attached Files

  • #2
    You may want to fit a restricted cubic splines model. Check -rcsgen-

    Comment


    • #3
      Is there a particular package required to use rcsgen?, I am taking a look now. Thanks!

      Comment


      • #4
        rcsgen is a package created by Paul Lambert (University of Leicester).

        Check one of the examples below:

        Code:
            sysuse auto, clear  
            rcsgen weight,    gen(rcs) df(3)
            regress mpg rcs1-rcs3
            predictnl pred = xb(), ci(lci uci)
            twoway (rarea lci uci weight, sort)  (scatter mpg  weight, sort) (line pred weight, sort lcolor(black)), legend(off)

        Comment


        • #5
          I've rarely seen data on GDP pc without thinking that it would be better logged.

          An even more fundamental problem is that you have panel data here, so expecting a simple curve across not just many countries but also several years is ambitious.

          Comment


          • #6
            Originally posted by Nick Cox View Post
            I've rarely seen data on GDP pc without thinking that it would be better logged.

            An even more fundamental problem is that you have panel data here, so expecting a simple curve across not just many countries but also several years is ambitious.
            I can isolate for one country and do it separately for a set of countries as well.

            Comment


            • #7
              Originally posted by Tiago Pereira View Post
              rcsgen is a package created by Paul Lambert (University of Leicester).

              Check one of the examples below:

              Code:
               sysuse auto, clear
              rcsgen weight, gen(rcs) df(3)
              regress mpg rcs1-rcs3
              predictnl pred = xb(), ci(lci uci)
              twoway (rarea lci uci weight, sort) (scatter mpg weight, sort) (line pred weight, sort lcolor(black)), legend(off)
              Thank you! let me try it with my data

              Comment

              Working...
              X