Announcement

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

  • nlsur three stages estimation in one stage

    Hi,

    I have a database with elderly women, elderly men and elderly in couples. I want to use nlsur AIDS program from Poi (2008) to estimate an equation for elderly couples database using paramaters of individual elderly (men and women) estimation. So I first estimate the paramaters of elderly men and women (first and second stages) and then I use these paramaters in the elderly couples system (third stage). The problem is that I don’t consider the standard errors of first and second stages, then I would like to estimate all the system in one stage.

    Does anyone have any idea how I can do this? I am posting my code below.

    Thank you so much.


    - First stage – Elderly men

    program nlsuraids

    version 10

    syntax varlist (min=17 max=17) if, at(name)
    tokenize `varlist'

    args w1 w2 w3 w4 w5 lnp1 lnp2 lnp3 lnp4 lnp5 lnp6 lnexp escol_idoso idade_pesref transf_gover pof_96 pof_03


    tempname a1 a2 a3 a4 a5 a6

    scalar `a1' = `at'[1, 1]
    scalar `a2' = `at'[1, 2]
    scalar `a3' = `at'[1, 3]
    scalar `a4' = `at'[1, 4]
    scalar `a5' = `at'[1, 5]
    scalar `a6' = 1 - `a1' - `a2' - `a3' - `a4' - `a5'

    tempname b1 b2 b3 b4 b5 b6

    scalar `b1' = `at'[1, 6]
    scalar `b2' = `at'[1, 7]
    scalar `b3' = `at'[1, 8]
    scalar `b4' = `at'[1, 9]
    scalar `b5' = `at'[1, 10]
    scalar `b6' = - `b1' - `b2' - `b3' - `b4' - `b5'

    tempname g11 g12 g13 g14 g15 g16
    tempname g21 g22 g23 g24 g25 g26
    tempname g31 g32 g33 g34 g35 g36
    tempname g41 g42 g43 g44 g45 g46
    tempname g51 g52 g53 g54 g55 g56
    tempname g61 g62 g63 g64 g65 g66

    scalar `g11' = `at'[1, 11]
    scalar `g12' = `at'[1, 12]
    scalar `g13' = `at'[1, 13]
    scalar `g14' = `at'[1, 14]
    scalar `g15' = `at'[1, 15]
    scalar `g16' = - `g11' - `g12' - `g13' - `g14' - `g15'

    scalar `g21' = `g12'
    scalar `g22' = `at'[1, 16]
    scalar `g23' = `at'[1, 17]
    scalar `g24' = `at'[1, 18]
    scalar `g25' = `at'[1, 19]
    scalar `g26' = - `g21' - `g22' - `g23' - `g24' - `g25'

    scalar `g31' = `g13'
    scalar `g32' = `g23'
    scalar `g33' = `at'[1, 20]
    scalar `g34' = `at'[1, 21]
    scalar `g35' = `at'[1, 22]
    scalar `g36' = - `g31' - `g32' - `g33' - `g34' - `g35'

    scalar `g41' = `g14'
    scalar `g42' = `g24'
    scalar `g43' = `g34'
    scalar `g44' = `at'[1, 23]
    scalar `g45' = `at'[1, 24]
    scalar `g46' = - `g41' - `g42' - `g43' - `g44' - `g45'

    scalar `g51' = `g15'
    scalar `g52' = `g25'
    scalar `g53' = `g35'
    scalar `g54' = `g45'
    scalar `g55' = `at'[1, 25]
    scalar `g56' = - `g51' - `g52' - `g53' - `g54' - `g55'

    scalar `g61' = `g16'
    scalar `g62' = `g26'
    scalar `g63' = `g36'
    scalar `g64' = `g46'
    scalar `g65' = `g56'
    scalar `g66' = - `g61' - `g62' - `g63' - `g64' - `g65'

    tempname r11 r12 r13 r14 r15
    tempname r21 r22 r23 r24 r25
    tempname r31 r32 r33 r34 r35
    tempname r41 r42 r43 r44 r45
    tempname r51 r52 r53 r54 r55

    scalar `r11' = `at'[1, 26]
    scalar `r12' = `at'[1, 27]
    scalar `r13' = `at'[1, 28]
    scalar `r14' = `at'[1, 29]
    scalar `r15' = `at'[1, 30]

    scalar `r21' = `at'[1, 31]
    scalar `r22' = `at'[1, 32]
    scalar `r23' = `at'[1, 33]
    scalar `r24' = `at'[1, 34]
    scalar `r25' = `at'[1, 35]

    scalar `r31' = `at'[1, 36]
    scalar `r32' = `at'[1, 37]
    scalar `r33' = `at'[1, 38]
    scalar `r34' = `at'[1, 39]
    scalar `r35' = `at'[1, 40]

    scalar `r41' = `at'[1, 41]
    scalar `r42' = `at'[1, 42]
    scalar `r43' = `at'[1, 43]
    scalar `r44' = `at'[1, 44]
    scalar `r45' = `at'[1, 45]

    scalar `r51' = `at'[1, 46]
    scalar `r52' = `at'[1, 47]
    scalar `r53' = `at'[1, 48]
    scalar `r54' = `at'[1, 49]
    scalar `r55' = `at'[1, 50]


    quietly {
    *First get the price index
    *I set a_0 = 6
    tempvar lpindex
    gen double `lpindex' = 1.76 + `a1'*`lnp1' + `a2'*`lnp2'+ `a3'*`lnp3' + `a4'*`lnp4'+ `a5'*`lnp5'+ `a6'*`lnp6'

    forvalues i = 1/6 {
    forvalues j = 1/6 {
    replace `lpindex' = `lpindex' + 0.5*`g`i'`j''*`lnp`i''*`lnp`j''
    }
    }

    /* Finally, the expenditure shares for 5 of the 6
    goods (the equation 6 is dropped to avoid singularity) */


    replace `w1' = `a1' + `g11'*lnp1 + `g12'*lnp2 + `g13'*lnp3 + `g14'*lnp4 + `g15'*lnp5 + `g16'*lnp6 + `b1'*(lnexp - `lpindex') + `r11'*`escol_idoso' + `r12'*`idade_pesref' + `r13'*`transf_gover' + `r14'*`pof_96' + `r15'*`pof_03'

    replace `w2' = `a2' + `g21'*lnp1 + `g22'*lnp2 + `g23'*lnp3 + `g24'*lnp4 + `g25'*lnp5 + `g26'*lnp6 + `b2'*(lnexp - `lpindex') + `r21'*`escol_idoso' + `r22'*`idade_pesref' + `r23'*`transf_gover' + `r24'*`pof_96' + `r25'*`pof_03'

    replace `w3' = `a3' + `g31'*lnp1 + `g32'*lnp2 + `g33'*lnp3 + `g34'*lnp4 + `g35'*lnp5 + `g36'*lnp6 + `b3'*(lnexp - `lpindex') + `r31'*`escol_idoso' + `r32'*`idade_pesref' + `r33'*`transf_gover' + `r34'*`pof_96' + `r35'*`pof_03'

    replace `w4' = `a4' + `g41'*lnp1 + `g42'*lnp2 + `g43'*lnp3 + `g44'*lnp4 + `g45'*lnp5 + `g46'*lnp6 + `b4'*(lnexp - `lpindex') + `r41'*`escol_idoso' + `r42'*`idade_pesref' + `r43'*`transf_gover' + `r44'*`pof_96' + `r45'*`pof_03'

    replace `w5' = `a5' + `g51'*lnp1 + `g52'*lnp2 + `g53'*lnp3 + `g54'*lnp4 + `g55'*lnp5 + `g56'*lnp6 + `b5'*(lnexp - `lpindex') + `r51'*`escol_idoso' + `r52'*`idade_pesref' + `r53'*`transf_gover' + `r54'*`pof_96' + `r55'*`pof_03'

    }
    end

    nlsur aids @ w1 w2 w3 w4 w5 lnp1 lnp2 lnp3 lnp4 lnp5 lnp6 lnexp escol_idoso idade_pesref transf_gover pof_96 pof_03 if elderly_man==1, ifgnls nequations(5) param(a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 g11 g12 g13 g14 g15 g22 g23 g24 g25 g33 g34 g35 g44 g45 g55 r11 r12 r13 r14 r15 r21 r22 r23 r24 r25 r31 r32 r33 r34 r35 r41 r42 r43 r44 r45 r51 r52 r53 r54 r55)


    - Second stage – Elderly women

    program nlsuraids

    version 10

    syntax varlist(min=17 max=17) if, at(name)
    tokenize `varlist'

    args w1 w2 w3 w4 w5 lnp1 lnp2 lnp3 lnp4 lnp5 lnp6 lnexp escol_idosa idade_pesref transf_gover pof_96 pof_03


    tempname a1 a2 a3 a4 a5 a6

    scalar `a1' = `at'[1, 1]
    scalar `a2' = `at'[1, 2]
    scalar `a3' = `at'[1, 3]
    scalar `a4' = `at'[1, 4]
    scalar `a5' = `at'[1, 5]
    scalar `a6' = 1 - `a1' - `a2' - `a3' - `a4' - `a5'


    tempname b1 b2 b3 b4 b5 b6

    scalar `b1' = `at'[1, 6]
    scalar `b2' = `at'[1, 7]
    scalar `b3' = `at'[1, 8]
    scalar `b4' = `at'[1, 9]
    scalar `b5' = `at'[1, 10]
    scalar `b6' = - `b1' - `b2' - `b3' - `b4' - `b5'


    tempname g11 g12 g13 g14 g15 g16
    tempname g21 g22 g23 g24 g25 g26
    tempname g31 g32 g33 g34 g35 g36
    tempname g41 g42 g43 g44 g45 g46
    tempname g51 g52 g53 g54 g55 g56
    tempname g61 g62 g63 g64 g65 g66

    scalar `g11' = `at'[1, 11]
    scalar `g12' = `at'[1, 12]
    scalar `g13' = `at'[1, 13]
    scalar `g14' = `at'[1, 14]
    scalar `g15' = `at'[1, 15]
    scalar `g16' = - `g11' - `g12' - `g13' - `g14' - `g15'

    scalar `g21' = `g12'
    scalar `g22' = `at'[1, 16]
    scalar `g23' = `at'[1, 17]
    scalar `g24' = `at'[1, 18]
    scalar `g25' = `at'[1, 19]
    scalar `g26' = - `g21' - `g22' - `g23' - `g24' - `g25'

    scalar `g31' = `g13'
    scalar `g32' = `g23'
    scalar `g33' = `at'[1, 20]
    scalar `g34' = `at'[1, 21]
    scalar `g35' = `at'[1, 22]
    scalar `g36' = - `g31' - `g32' - `g33' - `g34' - `g35'

    scalar `g41' = `g14'
    scalar `g42' = `g24'
    scalar `g43' = `g34'
    scalar `g44' = `at'[1, 23]
    scalar `g45' = `at'[1, 24]
    scalar `g46' = - `g41' - `g42' - `g43' - `g44' - `g45'

    scalar `g51' = `g15'
    scalar `g52' = `g25'
    scalar `g53' = `g35'
    scalar `g54' = `g45'
    scalar `g55' = `at'[1, 25]
    scalar `g56' = - `g51' - `g52' - `g53' - `g54' - `g55'

    scalar `g61' = `g16'
    scalar `g62' = `g26'
    scalar `g63' = `g36'
    scalar `g64' = `g46'
    scalar `g65' = `g56'
    scalar `g66' = - `g61' - `g62' - `g63' - `g64' - `g65'

    tempname r11 r12 r13 r14 r15
    tempname r21 r22 r23 r24 r25
    tempname r31 r32 r33 r34 r35
    tempname r41 r42 r43 r44 r45
    tempname r51 r52 r53 r54 r55

    scalar `r11' = `at'[1, 26]
    scalar `r12' = `at'[1, 27]
    scalar `r13' = `at'[1, 28]
    scalar `r14' = `at'[1, 29]
    scalar `r15' = `at'[1, 30]

    scalar `r21' = `at'[1, 31]
    scalar `r22' = `at'[1, 32]
    scalar `r23' = `at'[1, 33]
    scalar `r24' = `at'[1, 34]
    scalar `r25' = `at'[1, 35]

    scalar `r31' = `at'[1, 36]
    scalar `r32' = `at'[1, 37]
    scalar `r33' = `at'[1, 38]
    scalar `r34' = `at'[1, 39]
    scalar `r35' = `at'[1, 40]

    scalar `r41' = `at'[1, 41]
    scalar `r42' = `at'[1, 42]
    scalar `r43' = `at'[1, 43]
    scalar `r44' = `at'[1, 44]
    scalar `r45' = `at'[1, 45]

    scalar `r51' = `at'[1, 46]
    scalar `r52' = `at'[1, 47]
    scalar `r53' = `at'[1, 48]
    scalar `r54' = `at'[1, 49]
    scalar `r55' = `at'[1, 50]


    quietly {
    *First get the price index
    *I set a_0 = 6
    tempvar lpindex
    gen double `lpindex' = 1.64 + `a1'*`lnp1' + `a2'*`lnp2'+ `a3'*`lnp3' + `a4'*`lnp4'+ `a5'*`lnp5'+ `a6'*`lnp6'

    forvalues i = 1/6 {
    forvalues j = 1/6 {
    replace `lpindex' = `lpindex' + 0.5*`g`i'`j''*`lnp`i''*`lnp`j''
    }
    }

    /* Finally, the expenditure shares for 5 of the 6
    goods (the equation 6 is dropped to avoid singularity) */


    replace `w1' = `a1' + `g11'*lnp1 + `g12'*lnp2 + `g13'*lnp3 + `g14'*lnp4 + `g15'*lnp5 + `g16'*lnp6 + `b1'*(lnexp - `lpindex') + `r11'*`escol_idosa' + `r12'*`idade_pesref' + `r13'*`transf_gover' + `r14'*`pof_96' + `r15'*`pof_03'

    replace `w2' = `a2' + `g21'*lnp1 + `g22'*lnp2 + `g23'*lnp3 + `g24'*lnp4 + `g25'*lnp5 + `g26'*lnp6 + `b2'*(lnexp - `lpindex') + `r21'*`escol_idosa' + `r22'*`idade_pesref' + `r23'*`transf_gover' + `r24'*`pof_96' + `r25'*`pof_03'

    replace `w3' = `a3' + `g31'*lnp1 + `g32'*lnp2 + `g33'*lnp3 + `g34'*lnp4 + `g35'*lnp5 + `g36'*lnp6 + `b3'*(lnexp - `lpindex') + `r31'*`escol_idosa' + `r32'*`idade_pesref' + `r33'*`transf_gover' + `r34'*`pof_96' + `r35'*`pof_03'

    replace `w4' = `a4' + `g41'*lnp1 + `g42'*lnp2 + `g43'*lnp3 + `g44'*lnp4 + `g45'*lnp5 + `g46'*lnp6 + `b4'*(lnexp - `lpindex') + `r41'*`escol_idosa' + `r42'*`idade_pesref' + `r43'*`transf_gover' + `r44'*`pof_96' + `r45'*`pof_03'

    replace `w5' = `a5' + `g51'*lnp1 + `g52'*lnp2 + `g53'*lnp3 + `g54'*lnp4 + `g55'*lnp5 + `g56'*lnp6 + `b5'*(lnexp - `lpindex') + `r51'*`escol_idosa' + `r52'*`idade_pesref' + `r53'*`transf_gover' + `r54'*`pof_96' + `r55'*`pof_03'

    }
    end


    nlsur aids @ w1 w2 w3 w4 w5 lnp1 lnp2 lnp3 lnp4 lnp5 lnp6 lnexp escol_idosa idade_pesref transf_gover pof_96 pof_03 if elderly_women==1, ifgnls nequations(5) param(a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 g11 g12 g13 g14 g15 g22 g23 g24 g25 g33 g34 g35 g44 g45 g55 r11 r12 r13 r14 r15 r21 r22 r23 r24 r25 r31 r32 r33 r34 r35 r41 r42 r43 r44 r45 r51 r52 r53 r54 r55)


    - Third stage – Ederly in couples ("f" - female elderly parameters and "m" - male elderly parameters)

    program nlsuraidscouple

    version 10

    syntax varlist(min=22 max=22) if, at(name)
    tokenize `varlist'

    args w1 w2 w3 w4 w5 p1 p2 p3 p4 p5 p6 lnexp escol_idosa idade_idosa transf_gover pof_96 pof_03 escol_idoso idade_idoso dif_renda time_trend Mc

    tempname af1 af2 af3 af4 af5 af6

    scalar `af1' = 0.3508571
    scalar `af2' = 0.5367001
    scalar `af3' = 0.0963043
    scalar `af4' = 0.0466717
    scalar `af5' = -0.0376753
    scalar `af6' = 1 - `af1' - `af2' - `af3' - `af4' - `af5'

    tempname bf1 bf2 bf3 bf4 bf5 bf6

    scalar `bf1' = -0.010056
    scalar `bf2' = -0.0262115
    scalar `bf3' = -0.0006611
    scalar `bf4' = 0.0187041
    scalar `bf5' = 0.0034199
    scalar `bf6' = - `bf1' - `bf2' - `bf3' - `bf4' - `bf5'

    tempname gf11 gf12 gf13 gf14 gf15 gf16
    tempname gf21 gf22 gf23 gf24 gf25 gf26
    tempname gf31 gf32 gf33 gf34 gf35 gf36
    tempname gf41 gf42 gf43 gf44 gf45 gf46
    tempname gf51 gf52 gf53 gf54 gf55 gf56
    tempname gf61 gf62 gf63 gf64 gf65 gf66

    scalar `gf11' = 0.2224772
    scalar `gf12' = -0.1451204
    scalar `gf13' = -0.0234329
    scalar `gf14' = -0.0138873
    scalar `gf15' = -0.0199647
    scalar `gf16' = - `gf11' - `gf12' - `gf13' - `gf14' - `gf15'

    scalar `gf21' = `gf12'
    scalar `gf22' = 0.0033397
    scalar `gf23' = -0.015484
    scalar `gf24' = 0.0164493
    scalar `gf25' = 0.1482434
    scalar `gf26' = - `gf21' - `gf22' - `gf23' - `gf24' - `gf25'

    scalar `gf31' = `gf13'
    scalar `gf32' = `gf23'
    scalar `gf33' = 0.0459164
    scalar `gf34' = 0.0168696
    scalar `gf35' = 0.0016994
    scalar `gf36' = - `gf31' - `gf32' - `gf33' - `gf34' - `gf35'

    scalar `gf41' = `gf14'
    scalar `gf42' = `gf24'
    scalar `gf43' = `gf34'
    scalar `gf44' = -0.0403316
    scalar `gf45' = 0.0246683
    scalar `gf46' = - `gf41' - `gf42' - `gf43' - `gf44' - `gf45'

    scalar `gf51' = `gf15'
    scalar `gf52' = `gf25'
    scalar `gf53' = `gf35'
    scalar `gf54' = `gf45'
    scalar `gf55' = -0.1945782
    scalar `gf56' = - `gf51' - `gf52' - `gf53' - `gf54' - `gf55'

    scalar `gf61' = `gf16'
    scalar `gf62' = `gf26'
    scalar `gf63' = `gf36'
    scalar `gf64' = `gf46'
    scalar `gf65' = `gf56'
    scalar `gf66' = - `gf61' - `gf62' - `gf63' - `gf64' - `gf65'

    tempname rf11 rf12 rf13 rf14 rf15
    tempname rf21 rf22 rf23 rf24 rf25
    tempname rf31 rf32 rf33 rf34 rf35
    tempname rf41 rf42 rf43 rf44 rf45
    tempname rf51 rf52 rf53 rf54 rf55

    scalar `rf11' = -0.0085576
    scalar `rf12' = -0.0011624
    scalar `rf13' = 0.0062469
    scalar `rf14' = 0.1311077
    scalar `rf15' = -0.0040328

    scalar `rf21' = 0.0033389
    scalar `rf22' = 0.0028931
    scalar `rf23' = -0.0135272
    scalar `rf24' = -0.3711398
    scalar `rf25' = -0.0667765

    scalar `rf31' = 0.0002489
    scalar `rf32' = -0.0009382
    scalar `rf33' = -0.0000248
    scalar `rf34' = 0.0029681
    scalar `rf35' = -0.0084301

    scalar `rf41' = 0.0032483
    scalar `rf42' = -0.0021089
    scalar `rf43' = 0.0078469
    scalar `rf44' = 0.0332397
    scalar `rf45' = 0.0031179

    scalar `rf51' = -0.001098
    scalar `rf52' = 0.0020926
    scalar `rf53' = 0.0019834
    scalar `rf54' = 0.1512718
    scalar `rf55' = 0.092456

    tempname am1 am2 am3 am4 am5 am6

    scalar `am1' = 0.4193619
    scalar `am2' = 0.3890712
    scalar `am3' = 0.0904862
    scalar `am4' = -0.0855106
    scalar `am5' = 0.0100474
    scalar `am6' = 1 - `am1' - `am2' - `am3' - `am4' - `am5'

    tempname bm1 bm2 bm3 bm4 bm5 bm6

    scalar `bm1' = -0.0218672
    scalar `bm2' = -0.0337519
    scalar `bm3' = -0.0056566
    scalar `bm4' = 0.057614
    scalar `bm5' = 0.0014422
    scalar `bm6' = - `bm1' - `bm2' - `bm3' - `bm4' - `bm5'

    tempname gm11 gm12 gm13 gm14 gm15 gm16
    tempname gm21 gm22 gm23 gm24 gm25 gm26
    tempname gm31 gm32 gm33 gm34 gm35 gm36
    tempname gm41 gm42 gm43 gm44 gm45 gm46
    tempname gm51 gm52 gm53 gm54 gm55 gm56
    tempname gm61 gm62 gm63 gm64 gm65 gm66

    scalar `gm11' = 0.2023128
    scalar `gm12' = -0.0629833
    scalar `gm13' = -0.0352643
    scalar `gm14' = -0.028009
    scalar `gm15' = 0.0611543
    scalar `gm16' = - `gm11' - `gm12' - `gm13' - `gm14' - `gm15'

    scalar `gm21' = `gm12'
    scalar `gm22' = -0.0978133
    scalar `gm23' = 0.0086363
    scalar `gm24' = 0.1436452
    scalar `gm25' = -0.0428634
    scalar `gm26' = - `gm21' - `gm22' - `gm23' - `gm24' - `gm25'

    scalar `gm31' = `gm13'
    scalar `gm32' = `gm23'
    scalar `gm33' = 0.0032568
    scalar `gm34' = 0.0364523
    scalar `gm35' = -0.0111659
    scalar `gm36' = - `gm31' - `gm32' - `gm33' - `gm34' - `gm35'

    scalar `gm41' = `gm14'
    scalar `gm42' = `gm24'
    scalar `gm43' = `gm34'
    scalar `gm44' = -0.0587932
    scalar `gm45' = -0.0576495
    scalar `gm46' = - `gm41' - `gm42' - `gm43' - `gm44' - `gm45'

    scalar `gm51' = `gm15'
    scalar `gm52' = `gm25'
    scalar `gm53' = `gm35'
    scalar `gm54' = `gm45'
    scalar `gm55' = -0.0534491
    scalar `gm56' = - `gm51' - `gm52' - `gm53' - `gm54' - `gm55'

    scalar `gm61' = `gm16'
    scalar `gm62' = `gm26'
    scalar `gm63' = `gm36'
    scalar `gm64' = `gm46'
    scalar `gm65' = `gm56'
    scalar `gm66' = - `gm61' - `gm62' - `gm63' - `gm64' - `gm65'

    tempname rm11 rm12 rm13 rm14 rm15
    tempname rm21 rm22 rm23 rm24 rm25
    tempname rm31 rm32 rm33 rm34 rm35
    tempname rm41 rm42 rm43 rm44 rm45
    tempname rm51 rm52 rm53 rm54 rm55

    scalar `rm11' = -0.0067218
    scalar `rm12' = -0.0007283
    scalar `rm13' = -0.0024119
    scalar `rm14' = 0.1120134
    scalar `rm15' = 0.0101155

    scalar `rm21' = 0.0033375
    scalar `rm22' = 0.0049875
    scalar `rm23' = -0.019966
    scalar `rm24' = -0.3090848
    scalar `rm25' = -0.0482838

    scalar `rm31' = -0.0002138
    scalar `rm32' = -0.0001562
    scalar `rm33' = -0.0141397
    scalar `rm34' = 0.001623
    scalar `rm35' = -0.0179029

    scalar `rm41' = 0.0010057
    scalar `rm42' = -0.0030705
    scalar `rm43' = 0.0020591
    scalar `rm44' = 0.1036636
    scalar `rm45' = 0.0336761

    scalar `rm51' = 0.0018315
    scalar `rm52' = 0.0011459
    scalar `rm53' = 0.0110968
    scalar `rm54' = 0.0208002
    scalar `rm55' = 0.0227367

    tempname s1 s2 s3 s4 s5

    scalar `s1' = `at'[1, 1]
    scalar `s2' = `at'[1, 2]
    scalar `s3' = `at'[1, 3]
    scalar `s4' = `at'[1, 4]
    scalar `s5' = `at'[1, 5]

    tempname t1 t2 t3 t4 t5 t6

    scalar `t1' = `at'[1, 6]
    scalar `t2' = `at'[1, 7]
    scalar `t3' = `at'[1, 8]
    scalar `t4' = `at'[1, 9]
    scalar `t5' = `at'[1, 10]
    scalar `t6' = `at'[1, 11]


    quietly {
    *Sharing Rule
    tempvar sharingrule
    generate double `sharingrule' = 0
    replace `sharingrule'=exp(`s1'+`s2'*`dif_renda'+`s3'*`time _trend'+`s4'*`escol_idosa'+`s5'*`Mc')/(1+exp(`s1'+`s2'*`dif_renda'+`s3'*`time_trend'+`s4 '*`escol_idosa'+`s5'*`Mc'))


    /* The Consumption Techonology on Couple Quaids model: */
    tempvar constechn1
    generate double `constechn1' = 0
    replace `constechn1'=(((1+(exp(`t1')/(1+exp(`t1'))))/2)*`p1')/exp(`lnexp')
    replace `constechn1'=ln(`constechn1')

    tempvar constechn2
    generate double `constechn2' = 0
    replace `constechn2'=(((1+(exp(`t2')/(1+exp(`t2'))))/2)*`p2')/exp(`lnexp')
    replace `constechn2'=ln(`constechn2')

    tempvar constechn3
    generate double `constechn3' = 0
    replace `constechn3'=(((1+(exp(`t3')/(1+exp(`t3'))))/2)*`p3')/exp(`lnexp')
    replace `constechn3'=ln(`constechn3')

    tempvar constechn4
    generate double `constechn4' = 0
    replace `constechn4'=(((1+(exp(`t4')/(1+exp(`t4'))))/2)*`p4')/exp(`lnexp')
    replace `constechn4'=ln(`constechn4')

    tempvar constechn5
    generate double `constechn5' = 0
    replace `constechn5'=(((1+(exp(`t5')/(1+exp(`t5'))))/2)*`p5')/exp(`lnexp')
    replace `constechn5'=ln(`constechn5')

    tempvar constechn6
    generate double `constechn6' = 0
    replace `constechn6'=(((1+(exp(`t6')/(1+exp(`t6'))))/2)*`p6')/exp(`lnexp')
    replace `constechn6'=ln(`constechn6')


    * First get the price index
    * I set a_0 = 6
    tempvar lpindexf
    gen double `lpindexf' = 0.85 + `af1'*`constechn1' + `af2'*`constechn2'+ `af3'*`constechn3' + `af4'*`constechn4'+ `af5'*`constechn5'+ `af6'*`constechn6'

    forvalues i = 1/6 {
    forvalues j = 1/6 {
    replace `lpindexf' = `lpindexf' + 0.5*`gf`i'`j''*`constechn`i''*`constechn`j''
    }
    }
    tempvar lpindexm
    gen double `lpindexm' = 0.96 + `am1'*`constechn1' + `am2'*`constechn2'+ `am3'*`constechn3' + `am4'*`constechn4'+ `am5'*`constechn5'+ `am6'*`constechn6'

    forvalues i = 1/6 {
    forvalues j = 1/6 {
    replace `lpindexm' = `lpindexm' + 0.5*`gm`i'`j''*`constechn`i''*`constechn`j''
    }
    }
    /* Finally, the expenditure shares */


    tempvar wf1
    generate double `wf1' = 0
    replace `wf1' = `af1' + `gf11'*`constechn1' + `gf12'*`constechn2' + `gf13'*`constechn3' + `gf14'*`constechn4' + `gf15'*`constechn5' + `gf16'*`constechn6' + `bf1'*(ln(`sharingrule') - `lpindexf') + `rf11'*`escol_idosa' + `rf12'*`idade_idosa' + `rf13'*`transf_gover' + `rf14'*`pof_96' + `rf15'*`pof_03'

    tempvar wf2
    generate double `wf2' = 0
    replace `wf2' = `af2' + `gf21'*`constechn1' + `gf22'*`constechn2' + `gf23'*`constechn3' + `gf24'*`constechn4' + `gf25'*`constechn5' + `gf26'*`constechn6' + `bf2'*(ln(`sharingrule') - `lpindexf') + `rf21'*`escol_idosa' + `rf22'*`idade_idosa' + `rf23'*`transf_gover' + `rf24'*`pof_96' + `rf25'*`pof_03'

    tempvar wf3
    generate double `wf3' = 0
    replace `wf3' = `af3' + `gf31'*`constechn1' + `gf32'*`constechn2' + `gf33'*`constechn3' + `gf34'*`constechn4' + `gf35'*`constechn5' + `gf36'*`constechn6' + `bf3'*(ln(`sharingrule') - `lpindexf') + `rf31'*`escol_idosa' + `rf32'*`idade_idosa' + `rf33'*`transf_gover' + `rf34'*`pof_96' + `rf35'*`pof_03'

    tempvar wf4
    generate double `wf4' = 0
    replace `wf4' = `af4' + `gf41'*`constechn1' + `gf42'*`constechn2' + `gf43'*`constechn3' + `gf44'*`constechn4' + `gf45'*`constechn5' + `gf46'*`constechn6' + `bf4'*(ln(`sharingrule') - `lpindexf') + `rf41'*`escol_idosa' + `rf42'*`idade_idosa' + `rf43'*`transf_gover' + `rf44'*`pof_96' + `rf45'*`pof_03'

    tempvar wf5
    generate double `wf5' = 0
    replace `wf5' = `af5' + `gf51'*`constechn1' + `gf52'*`constechn2' + `gf53'*`constechn3' + `gf54'*`constechn4' + `gf55'*`constechn5' + `gf56'*`constechn6' + `bf5'*(ln(`sharingrule') - `lpindexf') + `rf51'*`escol_idosa' + `rf52'*`idade_idosa' + `rf53'*`transf_gover' + `rf54'*`pof_96' + `rf55'*`pof_03'

    tempvar wm1
    generate double `wm1' = 0
    replace `wm1' = `am1' + `gm11'*`constechn1' + `gm12'*`constechn2' + `gm13'*`constechn3' + `gm14'*`constechn4' + `gm15'*`constechn5' + `gm16'*`constechn6' + `bm1'*(ln(`sharingrule') - `lpindexm') + `rm11'*`escol_idoso' + `rm12'*`idade_idoso' + `rm13'*`transf_gover' + `rm14'*`pof_96' + `rm15'*`pof_03'

    tempvar wm2
    generate double `wm2' = 0
    replace `wm2' = `am2' + `gm21'*`constechn1' + `gm22'*`constechn2' + `gm23'*`constechn3' + `gm24'*`constechn4' + `gm25'*`constechn5' + `gm26'*`constechn6' + `bm2'*(ln(`sharingrule') - `lpindexm') + `rm21'*`escol_idoso' + `rm22'*`idade_idoso' + `rm23'*`transf_gover' + `rm24'*`pof_96' + `rm25'*`pof_03'

    tempvar wm3
    generate double `wm3' = 0
    replace `wm3' = `am3' + `gm31'*`constechn1' + `gm32'*`constechn2' + `gm33'*`constechn3' + `gm34'*`constechn4' + `gm35'*`constechn5' + `gm36'*`constechn6' + `bm3'*(ln(`sharingrule') - `lpindexm') + `rm31'*`escol_idoso' + `rm32'*`idade_idoso' + `rm33'*`transf_gover' + `rm34'*`pof_96' + `rm35'*`pof_03'

    tempvar wm4
    generate double `wm4' = 0
    replace `wm4' = `am4' + `gm41'*`constechn1' + `gm42'*`constechn2' + `gm43'*`constechn3' + `gm44'*`constechn4' + `gm45'*`constechn5' + `gm46'*`constechn6' + `bm4'*(ln(`sharingrule') - `lpindexm') + `rm41'*`escol_idoso' + `rm42'*`idade_idoso' + `rm43'*`transf_gover' + `rm44'*`pof_96' + `rm45'*`pof_03'

    tempvar wm5
    generate double `wm5' = 0
    replace `wm5' = `am5' + `gm51'*`constechn1' + `gm52'*`constechn2' + `gm53'*`constechn3' + `gm54'*`constechn4' + `gm55'*`constechn5' + `gm56'*`constechn6' + `bm5'*(ln(`sharingrule') - `lpindexm') + `rm51'*`escol_idoso' + `rm52'*`idade_idoso' + `rm53'*`transf_gover' + `rm54'*`pof_96' + `rm55'*`pof_03'


    replace `w1' = `sharingrule'*`wf1' + (1 - `sharingrule')*`wm1'

    replace `w2' = `sharingrule'*`wf2' + (1 - `sharingrule')*`wm2'

    replace `w3' = `sharingrule'*`wf3' + (1 - `sharingrule')*`wm3'

    replace `w4' = `sharingrule'*`wf4' + (1 - `sharingrule')*`wm4'

    replace `w5' = `sharingrule'*`wf5' + (1 - `sharingrule')*`wm5'


    }
    end


    nlsur aidscouple @ w1 w2 w3 w4 w5 p1 p2 p3 p4 p5 p6 lnexp escol_idosa idade_idosa transf_gover pof_96 pof_03 escol_idoso idade_idoso dif_renda time_trend Mc if elderly_couple==1, ifgnls nequations(5) param(s1 s2 s3 s4 s5 t1 t2 t3 t4 t5 t6)
Working...
X