Announcement

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

  • Linearity and functional form

    Dear Stata users,

    I am not sure wheter this is appropriate since this may be more of a general statistical question rather than a specific stata question, however I am at the ends of my wits. I am trying to adress the linearity assumption in my regression but don't know how to transform my data in order to get a linear relation between my variables. My regression is shaped as follows: aandnbouw = a0+ a1*expchfrwws + a2*bouwk. And it is the variable: expchfrwws which is the problem, this is a fraction of the current value divided by the last value (I did this earlier in my analysis). My values are therefore clustered around 1, and any deviations from 1 indicate the change. The problem arises from the fact that in relation to my dependend variable my observations represent a bellshape around 1, instead of a linear line. I have tried different functional forms but they don't create a linear relation so I was wondering what else I can try.


    With kind regards,

    Wouter

    my data:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(aandnbouw bouwk expchfrwws expchfrwwsln expchfrwwssq expchfrwwssqrt resh2 predh2)
      .04281345     .         .            .         .         .             .          .
     .033557046 .0897 1.0373883    .03670633 1.0761745 1.0185226   -.000508426 .034065474
      .02197802 .0438  .9981695 -.0018321957  .9963423  .9990843 -.00028322366 .022261247
              0 .0302  .9335508   -.06875986  .8715172  .9662043   -.017486159 .017486159
      .00862069     .         .            .         .         .             .          .
     .019417476 .0897  .8591362   -.15182786   .738115   .926896    -.01035117 .029768646
     .009009009 .0438   .990261  -.009786716  .9806169  .9951186     -.0130616  .02207061
              0 .0302  .8618019   -.14872982  .7427025  .9283329   -.015756628 .015756628
     .015748031     .         .            .         .         .             .          .
     .018541409 .0897  .9142607   -.08963947  .8358727  .9561698   -.012556033  .03109744
      .02794411 .0302  .9586955    -.0421818   .919097    .97913    .009851835 .018092278
      .02720207     .         .            .         .         .             .          .
     .025824964 .0897  .9309537   -.07154569  .8666748  .9648594   -.005674868 .031499833
     .018813314 .0438  .9937519  -.006267718  .9875428  .9968711  -.0033414445  .02215476
     .017216643 .0302  .8798767   -.12797353   .774183  .9380174   .0010243183 .016192324
     .016877636     .         .            .         .         .             .          .
      .02487562 .0897  .8901986   -.11631064  .7924536  .9435034   -.005641796  .03051742
     .004651163 .0438 1.0534533    .05207365 1.1097639 1.0263788    -.01894272  .02359388
     .010830325 .0302  1.016707   .016568918  1.033693 1.0083189   -.008660338 .019490663
      .02505219     .         .            .         .         .             .          .
     .035326086 .0897  .9647834   -.03585169  .9308069  .9822339   .0030107796 .032315306
      .01459854 .0438 1.0652007    .06316322 1.1346525 1.0320857   -.009278515 .023877054
     .007058823 .0302 1.0804205     .0773503 1.1673084 1.0394328   -.013967675   .0210265
      .03364486     .         .            .         .         .             .          .
      .04010025 .0897  .9743371  -.025997935  .9493328  .9870852    .007554648 .032545604
      .01201923 .0438 1.0635302    .06159376 1.1310965  1.031276   -.011817557  .02383679
      .01590909 .0302  .9939817  -.006036464  .9879997  .9969863   -.003033773 .018942865
     .015727391     .         .            .         .         .             .          .
     .034582134 .0897 1.0264728   .026128465 1.0536464   1.01315   .0007797842  .03380235
    .0085227275 .0438 1.0862641    .08274441 1.1799698 1.0422399   -.015862068 .024384797
     .016438356 .0302  .9435007   -.05815817  .8901936  .9713396   -.001287647 .017726002
     .024213076     .         .            .         .         .             .          .
      .04054054 .0897  .9324746   -.06991335  .8695089  .9656473    .009004045 .031536493
     .018181818 .0438 1.0260408   .025707504 1.0527598 1.0129367   -.004751275 .022933094
      .01908397 .0302 1.1213764    .11455686  1.257485 1.0589507   -.002929784 .022013754
      .03197158     .         .            .         .         .             .          .
      .05756149 .0897  .9843128  -.015811514  .9688718  .9921254    .024775416  .03278607
      .03971119 .0438  1.036474    .03582456 1.0742784 1.0180737    .016526604  .02318459
      .02262837 .0302  .9506148    -.0506464  .9036684  .9749947    .004730884 .017897489
     .025996534     .         .            .         .         .             .          .
      .02830189 .0897  .9901514  -.009897413  .9803998  .9950635  -.0046249237 .032926813
      .02967359 .0438  .9859568   -.01414275  .9721108  .9929535    .007706736 .021966856
      .04651163 .0302 1.0637519    .06180222 1.1315682 1.0313835     .02588693   .0206247
      .03860072     .         .            .         .         .             .          .
      .04565217 .0897  .9851516  -.014959692  .9705238   .992548    .012845883 .032806292
     .029166667 .0438 1.0031111  .0031062944 1.0062319 1.0015544    .006786301 .022380367
     .007412399 .0302 1.0035435   .003537233 1.0070995 1.0017701   -.011760955 .019173354
       .0357313     .         .            .         .         .             .          .
       .0449391 .0897 1.0162537   .016123032 1.0327716 1.0080941    .011383086 .033556014
     .025758645 .0438 1.0768218   .074013926 1.1595452 1.0377003    .001601459 .024157185
     .018162947 .0302  .9950306  -.004981807  .9900858  .9975122  -.0008051999 .018968146
     .026734104     .         .            .         .         .             .          .
      .02416212 .0897  .9964938  -.003512345  .9929999  .9982454   -.008917578   .0330797
     .018411968 .0438 1.0703896    .06802272  1.145734 1.0345963   -.005590168 .024002137
     .015873017 .0302 1.0571929    .05561721 1.1176568 1.0281988  -.0045935735  .02046659
      .02157709     .         .            .         .         .             .          .
       .0390625 .0897 1.0144002   .014297545 1.0290079 1.0071744    .005551163 .033511337
      .05015406 .0438 1.0421103    .04124781 1.0859939  1.020838      .0268336 .023320455
     .023400474 .0302 1.0037163   .003709461 1.0074465 1.0018564    .004222954  .01917752
      .02022059     .         .            .         .         .             .          .
     .017561983 .0897  .9648458  -.035786945  .9309275  .9822657    -.01475483  .03231681
     .033472802 .0438 1.0343219    .03374605 1.0698218 1.0170162     .01034009  .02313271
     .014112903 .0302  .9210259   -.08226708  .8482888  .9597009  -.0030713384  .01718424
      .01716859     .         .            .         .         .             .          .
      .05271009 .0897 1.0184036   .018236352  1.037146 1.0091599    .019102253  .03360784
      .05202502 .0438 1.0621655    .06030975 1.1281955 1.0306141     .02822113  .02380389
     .025634106 .0302  .9458883   -.05563081  .8947046  .9725679     .00785055 .017783556
     .034328356     .         .            .         .         .             .          .
      .04942339 .0897  .9650158  -.035610836  .9312555  .9823521    .017102484  .03232091
     .017167382 .0438 1.0533696    .05199421 1.1095876  1.026338   -.006424482 .023591863
     .013977128 .0302 1.0315348    .03104778  1.064064  1.015645   -.005870965 .019848093
     .033936653     .         .            .         .         .             .          .
      .02696629 .0897  .8735083    -.1352376  .7630168  .9346167     -.0031488  .03011509
      .02772277 .0438 1.0166755   .016537962 1.0336291 1.0083033    .005015433  .02270734
      .03508772 .0302  .9531367   -.04799696  .9084696  .9762872    .017129438 .017958282
     .029498525     .         .            .         .         .             .          .
      .05555556 .0897  .9754826  -.024822913  .9515664  .9876652     .02298234 .032573216
     .011204482 .0438  .9961383  -.003869141  .9922916  .9980673   -.011007803 .022212286
     .010958904 .0302 1.0918279    .08785324 1.1920881 1.0449057   -.010342573 .021301476
      .04375804     .         .            .         .         .             .          .
     .024192024 .0897  .9620756   -.03866225  .9255894  .9808545   -.008058011 .032250036
      .05092593 .0438 1.0356493   .035028573 1.0725695 1.0176686    .027761215  .02316471
     .023696683 .0302  .8589138   -.15208673  .7377329   .926776    .008009676 .015687007
     .034013607     .         .            .         .         .             .          .
     .017268445 .0897  .9551433   -.04589393  .9122987  .9773143   -.014814483  .03208293
     .015490534 .0438 1.0280708   .027684044 1.0569296 1.0139383   -.007491494  .02298203
      .02121212 .0302  .9955622 -.0044476804  .9911441  .9977787   .0022311597  .01898096
     .015768725     .         .            .         .         .             .          .
      .03215859 .0897  .9576822    -.0432393  .9171552  .9786124 .000014460592  .03214413
      .05705329 .0438 1.0015376  .0015363806 1.0030775 1.0007685    .034710854 .022342434
      .01499086 .0302  .8935814   -.11251786  .7984877  .9452943   -.001531822 .016522681
      .00921659     .         .            .         .         .             .          .
     .009433962 .0897   .945767   -.05575899  .8944753  .9725056    -.02242295 .031856913
     .018867925 .0438  .9920532  -.007978533  .9841696  .9960187  -.0032458866  .02211381
     .008080808 .0302 1.0041698   .004161152  1.008357 1.0020827   -.011107643  .01918845
     .012801575     .         .            .         .         .             .          .
      .02263969 .0897  .9910277   -.00901278   .982136  .9955037   -.010308243 .032947935
     .028669724 .0438  1.037393    .03671081 1.0761842 1.0185249    .005462983  .02320674
     .022326674 .0302  .9236693    -.0794012  .8531649  .9610772    .005078714  .01724796
      .03891848     .         .            .         .         .             .          .
    end
    My code:
    Code:
    clear all
    clear all
    use "C:\Users\woute\OneDrive\Documenten\RUG\Master thesis\Data\Werkmap\Analyse data\WoON2006-2015_analyse_prep.dta"
    keep aandnbouw expchfrwws bouwk
    *Analyse------------------------------------------------------------------------*
    *h2
    drop if aandnbouw > 0.1
    gen expchfrwwsln = ln(expchfrwws)
    gen expchfrwwssq = expchfrwws^2
    gen expchfrwwssqrt = sqrt(expchfrwws)
    reg aandnbouw expchfrwws bouwk, robust
    predict resh2, residual
    predict predh2
    *1 Linearity and checking functional form
    cd "C:\Users\woute\OneDrive\Documenten\RUG\Master thesis\Figuren\H2"
    twoway (scatter aandnbouw expchfrwws, mcolor(ltblue)) (lowess aandnbouw expchfrwws) (lfit aandnbouw expchfrwws), legend(off)
    graph export expchfrwws.jpg, replace
    twoway (scatter aandnbouw expchfrwwsln, mcolor(ltblue)) (lowess aandnbouw expchfrwwsln) (lfit aandnbouw expchfrwwsln), legend(off)
    graph export expchfrwwsln.jpg, replace
    twoway (scatter aandnbouw expchfrwwssq, mcolor(ltblue)) (lowess aandnbouw expchfrwwssq) (lfit aandnbouw expchfrwwssq), legend(off)
    graph export expchfrwwssq.jpg, replace
    twoway (scatter aandnbouw expchfrwwssqrt, mcolor(ltblue)) (lowess aandnbouw expchfrwwssqrt) (lfit aandnbouw expchfrwwssqrt), legend(off)
    graph export expchfrwwssqrt.jpg, replace
    twoway (scatter aandnbouw bouwk, mcolor(ltblue)) (lowess aandnbouw bouwk) (lfit aandnbouw bouwk), legend(off)
    graph export lineariteitbouwk.jpg, replace
    Click image for larger version

Name:	expchfrwws.jpg
Views:	1
Size:	22.1 KB
ID:	1741825
    Click image for larger version

Name:	expchfrwwsln.jpg
Views:	1
Size:	21.9 KB
ID:	1741826
    Click image for larger version

Name:	expchfrwwssq.jpg
Views:	1
Size:	22.8 KB
ID:	1741827
    Click image for larger version

Name:	expchfrwwssqrt.jpg
Views:	1
Size:	22.5 KB
ID:	1741828

  • #2
    why are you trying to change your data rather than model the non-linearity; for example, (but remember that there is no data example here), I might model the above in a piecewise fashion with 3 pieces, the first and third being linear and the second being quadratic; you can use -mkspline- or -makespline- to set up the data; see
    Code:
    h mkspline
    h makespline

    Comment

    Working...
    X