Announcement

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

  • Issues with applying weights to imported dataset

    Hello fellow statalisters!

    I'm currently in the midst of writing my bachelor and I have been using stata a lot of this, but I am having some issues with applying weights to my data set. I only have access to the BE version, so I have had to download my data via SAS, export into Excel and import the variables i needed into stata from excel after filtering in excel.

    I'm very new to stata, so I require help on setting the weights, and hope someone can help me out. I am trying to add the weights called "X42001vægte" with

    svyset [aw=X42001vægte]

    but i get "aweights not allowed" r(101)

    I have a very lenthy amount of variables given by
    LÅNID, AGE, MARRIED, KIDS, HHmembers, FPL, INCOME, X7824balance, X7805initialb, X7815payment, X782frekvens, årlig, X7822IR, X7880leftschool, X7978, X7811førstebetalingsår, X9300grace, X7422IDR, X6809race, X6810race, X8021køn2erkvinder

    and i have tried a lot of different things, but I just cannot seem to find the right solution. I know you are supposed to set the psu as the main variables as far i as understand it, but i keep getting the same error.

    Hope someone can help

    best regards, Oliver

    Here is my full code for that particular dataset:
    . import excel "C:\Users\Oliver\Documents\bachelor data tester1 stata.xlsx", sheet("1.1") firstrow

    . expand 1000

    . gen inf=0.02

    . gen rf=0.03

    . gen wgrow=0.02


    gen pFIX=(X7805initialb*X7822IR/10000)/((-(1+X7822/10000)^(-10))+1)
    replace pFIX=0 if X7822IR==0
    gen max0=max(INCOME-1.5*FPL,0)
    replace pFIX=min(0.1*max0,pFIX) if X7422IDR==1
    *år1*

    . gen fpl1=FPL*exp(inf)
    . gen shock1=0.15*rnormal()
    . gen inc1=exp(shock1+wgrow+inf)*INCOME

    . gen b1=max(0,(X7824balance*(1+X7822IR/10000))-årlig)

    . gen p1=max(0,min(årlig*inc1/INCOME, pFIX, b1*(1+X7822IR/10000))) if årlig<pFIX

    . replace p1=max(0,min(årlig*inc1/INCOME, b1*(1+X7822IR/10000))) if årlig>=pFIX
    . replace p1=X7824balance if X7824balance-årlig==0 | X7824balance-årlig<0
    . replace b1=0 if 2020-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b1=0 if 2020-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b1=0 if 2020-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b1=0 if 2020-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år2*
    . gen fpl2=fpl1*exp(inf)
    . gen shock2=0.15*rnormal()
    . gen inc2=exp(shock2+wgrow+inf)*inc1
    . gen b2=max(0,b1*(1+X7822IR/10000)-p1)

    . gen p2=max(0,min(p1*inc2/inc1, pFIX, b2*(1+X7822IR/10000))) if p1<pFIX

    . replace p2=max(0,min(årlig*inc2/inc1, b2*(1+X7822IR/10000))) if p1>=pFIX
    . replace p2=b1 if b1-p1==0 | b1-p1<0
    . replace b2=0 if 2021-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b2=0 if 2021-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b2=0 if 2021-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b2=0 if 2021-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år3*
    . gen fpl3=fpl2*exp(inf)
    . gen shock3=0.15*rnormal()
    . gen inc3=exp(shock3+wgrow+inf)*inc2

    . gen b3=max(0,b2*(1+X7822IR/10000)-p2)

    . gen p3=max(0,min(p2*inc3/inc2, pFIX, b3*(1+X7822IR/10000))) if p2<pFIX

    . replace p3=max(0,min(p2*inc3/inc2, b3*(1+X7822IR/10000))) if p2>=pFIX
    . replace p3=b2 if b2-p2==0 | b2-p2<0
    . replace b3=0 if 2022-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b3=0 if 2022-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b3=0 if 2022-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b3=0 if 2022-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år4*
    . gen fpl4=fpl3*exp(inf)
    gen shock4=0.15*rnormal()
    . gen inc4=exp(shock4+wgrow+inf)*inc3

    . gen b4=max(0,b3*(1+X7822IR/10000)-p3)

    . gen p4=max(0,min(p3*inc4/inc3, pFIX, b4*(1+X7822IR/10000))) if p3<pFIX
    . replace p4=b3 if b3-p3==0 | b3-p3<0
    . replace p4=max(0,min(p3*inc4/inc3, b4*(1+X7822IR/10000))) if p3>=pFIX
    . replace b4=0 if 2023-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b4=0 if 2023-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b4=0 if 2023-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b4=0 if 2023-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år 5*
    . gen fpl5=fpl4*exp(inf)
    gen shock5=0.15*rnormal()
    . gen inc5=exp(shock5+wgrow+inf)*inc4

    . gen b5=max(0,b4*(1+X7822IR/10000)-p4)

    . gen p5=max(0,min(p4*inc5/inc4, pFIX, b5*(1+X7822IR/10000))) if p4<pFIX

    . replace p5=max(0,min(p4*inc5/inc4, b5*(1+X7822IR/10000))) if p4>=pFIX
    . replace p5=b4 if b4-p4==0 | b4-p4<0
    . replace b5=0 if 2024-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b5=0 if 2024-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b5=0 if 2024-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b5=0 if 2024-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år 6*
    . gen fpl6=fpl5*exp(inf)
    . gen shock6=0.15*rnormal()
    . gen inc6=exp(shock6+wgrow+inf)*inc5

    . gen b6=max(0,b5*(1+X7822IR/10000)-p5)

    . gen p6=max(0,min(p5*inc6/inc5, pFIX, b6*(1+X7822IR/10000))) if p5<pFIX

    . replace p6=max(0,min(p5*inc6/inc5, b6*(1+X7822IR/10000))) if p5>=pFIX
    . replace p6=b5 if b5-p5==0 | b5-p5<0
    . replace b6=0 if 2025-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b6=0 if 2025-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b6=0 if 2025-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b6=0 if 2025-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år 7*
    . gen fpl7=fpl6*exp(inf)
    . gen shock7=0.15*rnormal()
    . gen inc7=exp(shock7+wgrow+inf)*inc6

    . gen b7=max(0,b6*(1+X7822IR/10000)-p6)

    . gen p7=max(0,min(p6*inc7/inc6, pFIX, b7*(1+X7822IR/10000))) if p6<pFIX

    . replace p7=max(0,min(p6*inc7/inc6, b7*(1+X7822IR/10000))) if p6>=pFIX
    . replace p7=b6 if b6-p6==0 | b6-p6<0
    . replace b7=0 if 2026-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b7=0 if 2026-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b7=0 if 2026-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b7=0 if 2026-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år8*
    . gen fpl8=fpl7*exp(inf)
    . gen shock8=0.15*rnormal()
    . gen inc8=exp(shock8+wgrow+inf)*inc7

    . gen b8=max(0,b7*(1+X7822IR/10000)-p7)

    . gen p8=max(0,min(p7*inc8/inc7, pFIX, b8*(1+X7822IR/10000))) if p7<pFIX

    . replace p8=max(0,min(p7*inc8/inc7, b8*(1+X7822IR/10000))) if p7>=pFIX
    . replace p8=b7 if b7-p7==0 | b7-p7<0
    . replace b8=0 if 2027-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b8=0 if 2027-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b8=0 if 2027-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b8=0 if 2027-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år9*
    . gen fpl9=fpl8*exp(inf)
    . gen shock9=0.15*rnormal()
    . gen inc9=exp(shock9+wgrow+inf)*inc8

    . gen b9=max(0,b8*(1+X7822IR/10000)-p8)

    . gen p9=max(0,min(p8*inc9/inc8, pFIX, b9*(1+X7822IR/10000))) if p8<pFIX

    . replace p9=max(0,min(p8*inc9/inc8, b9*(1+X7822IR/10000))) if p8>=pFIX
    . replace p9=b8 if b8-p8==0 | b8-p8<0
    . replace b9=0 if 2028-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b9=0 if 2028-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b9=0 if 2028-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b9=0 if 2028-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år10*
    . gen fpl10=fpl9*exp(inf)
    . gen shock10=0.15*rnormal()
    . gen inc10=exp(shock10+wgrow+inf)*inc9

    . gen b10=max(0,b9*(1+X7822IR/10000)-p9)

    . gen p10=max(0,min(p9*inc10/inc9, pFIX, b10*(1+X7822IR/10000))) if p9<pFIX

    . replace p10=max(0,min(p9*inc10/inc9, b10*(1+X7822IR/10000))) if p9>=pFIX
    . replace p10=b9 if b9-p9==0 | b9-p9<0
    . replace b10=0 if 2029-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b10=0 if 2029-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b10=0 if 2029-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b10=0 if 2029-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år11*
    . gen fpl11=fpl10*exp(inf)
    . gen shock11=0.15*rnormal()
    . gen inc11=exp(shock11+wgrow+inf)*inc10

    . gen b11=max(0,b10*(1+X7822IR/10000)-p10)

    . gen p11=max(0,min(p10*inc11/inc10, pFIX, b11*(1+X7822IR/10000))) if p10<pFIX

    . replace p11=max(0,min(p10*inc11/inc10, b11*(1+X7822IR/10000))) if p10>=pFIX
    . replace p11=b11 if b11-p11==0 | b11-p11<0
    . replace b11=0 if 2030-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b11=0 if 2030-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b11=0 if 2030-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b11=0 if 2030-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år12*
    . gen fpl12=fpl11*exp(inf)
    . gen shock12=0.15*rnormal()
    . gen inc12=exp(shock12+wgrow+inf)*inc11

    . gen b12=max(0,b11*(1+X7822IR/10000)-p11)

    . gen p12=max(0,min(p11*inc12/inc11, pFIX, b12*(1+X7822IR/10000))) if p11<pFIX

    . replace p12=max(0,min(årlig*inc12/inc11, b12*(1+X7822IR/10000))) if p11>=pFIX
    . replace p12=b11 if b12-p11==0 | b11-p11<0
    . replace b12=0 if 2031-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b12=0 if 2031-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b12=0 if 2031-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b12=0 if 2031-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år13*
    . gen fpl13=fpl12*exp(inf)
    . gen shock13=0.15*rnormal()
    . gen inc13=exp(shock13+wgrow+inf)*inc12

    . gen b13=max(0,b12*(1+X7822IR/10000)-p12)

    . gen p13=max(0,min(p12*inc13/inc12, pFIX, b13*(1+X7822IR/10000))) if p12<pFIX

    . replace p13=max(0,min(p12*inc13/inc12, b13*(1+X7822IR/10000))) if p12>=pFIX
    . replace p13=b12 if b12-p12==0 | b12-p12<0
    . replace b13=0 if 2032-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b13=0 if 2032-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b13=0 if 2032-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b13=0 if 2032-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år14*
    . gen fpl14=fpl13*exp(inf)
    . gen shock14=0.15*rnormal()
    . gen inc14=exp(shock14+wgrow+inf)*inc13

    . gen b14=max(0,b13*(1+X7822IR/10000)-p13)

    . gen p14=max(0,min(p13*inc14/inc13, pFIX, b14*(1+X7822IR/10000))) if p13<pFIX

    . replace p14=max(0,min(p13*inc14/inc13, b14*(1+X7822IR/10000))) if p13>=pFIX
    . replace p14=b13 if b13-p13==0 | b13-p13<0
    . replace b14=0 if 2033-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b14=0 if 2033-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b14=0 if 2033-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b14=0 if 2033-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år 15*
    . gen fpl15=fpl14*exp(inf)
    . gen shock15=0.15*rnormal()
    . gen inc15=exp(shock15+wgrow+inf)*inc14

    . gen b15=max(0,b14*(1+X7822IR/10000)-p14)

    . gen p15=max(0,min(p14*inc15/inc14, pFIX, b15*(1+X7822IR/10000))) if p14<pFIX

    . replace p15=max(0,min(p14*inc15/inc14, b15*(1+X7822IR/10000))) if p14>=pFIX
    . replace p15=b14 if b14-p14==0 | b14-p14<0
    . replace b15=0 if 2034-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b15=0 if 2034-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b15=0 if 2034-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b15=0 if 2034-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år 16*
    . gen fpl16=fpl15*exp(inf)
    . gen shock16=0.15*rnormal()
    . gen inc16=exp(shock16+wgrow+inf)*inc15

    . gen b16=max(0,b15*(1+X7822IR/10000)-p15)

    . gen p16=max(0,min(p15*inc16/inc15, pFIX, b16*(1+X7822IR/10000))) if p15<pFIX

    . replace p16=max(0,min(p15*inc16/inc15, b16*(1+X7822IR/10000))) if p15>=pFIX
    . replace p16=b15 if b15-p15==0 | b15-p15<0
    . replace b16=0 if 2035-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b16=0 if 2035-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b16=0 if 2035-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b16=0 if 2035-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år 17*
    . gen fpl17=fpl16*exp(inf)
    . gen shock17=0.15*rnormal()
    . gen inc17=exp(shock17+wgrow+inf)*inc16

    . gen b17=max(0,b16*(1+X7822IR/10000)-p16)

    . gen p17=max(0,min(p16*inc17/inc16, pFIX, b17*(1+X7822IR/10000))) if p16<pFIX

    . replace p17=max(0,min(p16*inc17/inc16, b17*(1+X7822IR/10000))) if p16>=pFIX
    . replace p17=b16 if b16-p16==0 | b16-p16<0
    . replace b17=0 if 2036-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b17=0 if 2036-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b17=0 if 2036-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b17=0 if 2036-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år18*
    . gen fpl18=fpl17*exp(inf)
    . gen shock18=0.15*rnormal()
    . gen inc18=exp(shock18+wgrow+inf)*inc17

    . gen b18=max(0,b17*(1+X7822IR/10000)-p17)

    . gen p18=max(0,min(p17*inc18/inc17, pFIX, b18*(1+X7822IR/10000))) if p17<pFIX

    . replace p18=max(0,min(p17*inc18/inc17, b18*(1+X7822IR/10000))) if p17>=pFIX
    . replace p18=b17 if b17-p17==0 | b17-p17<0
    . replace b18=0 if 2037-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b18=0 if 2037-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b18=0 if 2037-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b18=0 if 2037-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år19*
    . gen fpl19=fpl18*exp(inf)
    . gen shock19=0.15*rnormal()
    . gen inc19=exp(shock19+wgrow+inf)*inc18

    . gen b19=max(0,b18*(1+X7822IR/10000)-p18)

    . gen p19=max(0,min(p18*inc19/inc18, pFIX, b19*(1+X7822IR/10000))) if p18<pFIX

    . replace p19=max(0,min(p18*inc19/inc18, b19*(1+X7822IR/10000))) if p18>=pFIX
    . replace p19=b18 if b18-p18==0 | b18-p18<0
    . replace b19=0 if 2038-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b19=0 if 2038-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b19=0 if 2038-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b19=0 if 2038-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år20*
    . gen fpl20=fpl19*exp(inf)
    . gen shock20=0.15*rnormal()
    . gen inc20=exp(shock20+wgrow+inf)*inc19

    . gen b20=max(0,b19*(1+X7822IR/10000)-p19)

    . gen p20=max(0,min(p19*inc20/inc19, pFIX, b20*(1+X7822IR/10000))) if p19<pFIX

    . replace p20=max(0,min(p19*inc20/inc19, b20*(1+X7822IR/10000))) if p19>=pFIX
    . replace p20=b19 if b20-p19==0 | b20-p20<0
    . replace b20=0 if 2039-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b20=0 if 2039-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b20=0 if 2039-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b20=0 if 2039-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år21*
    . gen fpl21=fpl20*exp(inf)
    . gen shock21=0.15*rnormal()
    . gen inc21=exp(shock21+wgrow+inf)*inc20

    . gen b21=max(0,b20*(1+X7822IR/10000)-p20)

    . gen p21=max(0,min(p20*inc21/inc20, pFIX, b21*(1+X7822IR/10000))) if p20<pFIX

    . replace p21=max(0,min(p20*inc21/inc20, b21*(1+X7822IR/10000))) if p20>=pFIX
    . replace p21=b20 if b20-p20==0 | b20-p20<0
    . replace b21=0 if 2040-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b21=0 if 2040-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b21=0 if 2040-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b21=0 if 2040-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år22*
    . gen fpl22=fpl21*exp(inf)
    . gen shock22=0.15*rnormal()
    . gen inc22=exp(shock22+wgrow+inf)*inc21

    . gen b22=max(0,b21*(1+X7822IR/10000)-p21)

    . gen p22=max(0,min(p21*inc22/inc21, pFIX, b22*(1+X7822IR/10000))) if p21<pFIX

    . replace p22=max(0,min(p21*inc22/inc21, b22*(1+X7822IR/10000))) if p21>=pFIX
    . replace p22=b21 if b21-p21==0 | b21-p21<0
    . replace b22=0 if 2041-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b22=0 if 2041-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b22=0 if 2041-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b22=0 if 2041-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år23*
    . gen fpl23=fpl22*exp(inf)
    . gen shock23=0.15*rnormal()
    . gen inc23=exp(shock23+wgrow+inf)*inc22

    . gen b23=max(0,b22*(1+X7822IR/10000)-p22)

    . gen p23=max(0,min(p22*inc23/inc22, pFIX, b23*(1+X7822IR/10000))) if p22<pFIX

    . replace p23=max(0,min(p22*inc23/inc22, b23*(1+X7822IR/10000))) if p22>=pFIX
    . replace p23=b22 if b22-p22==0 | b22-p22<0
    . replace b23=0 if 2042-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b23=0 if 2042-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b23=0 if 2042-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b23=0 if 2042-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år24*
    . gen fpl24=fpl23*exp(inf)
    . gen shock24=0.15*rnormal()
    . gen inc24=exp(shock24+wgrow+inf)*inc23

    . gen b24=max(0,b23*(1+X7822IR/10000)-p23)

    . gen p24=max(0,min(p23*inc23/inc23, pFIX, b24*(1+X7822IR/10000))) if p23<pFIX

    . replace p24=max(0,min(p24*inc23/inc22, b24*(1+X7822IR/10000))) if p23>=pFIX
    . replace p24=b23 if b23-p23==0 | b23-p23<0
    . replace b24=0 if 2043-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b24=0 if 2043-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b24=0 if 2043-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b18=0 if 2043-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år25*
    . gen fpl25=fpl24*exp(inf)
    . gen shock25=0.15*rnormal()
    . gen inc25=exp(shock25+wgrow+inf)*inc24

    . gen b25=max(0,b24*(1+X7822IR/10000)-p24)

    . gen p25=max(0,min(p24*inc25/inc24, pFIX, b25*(1+X7822IR/10000))) if p24<pFIX
    . replace p25=b24 if b24-p24==0 | b24-p24<0
    . replace p25=max(0,min(p24*inc25/inc24, b25*(1+X7822IR/10000))) if p24>=pFIX
    . replace b25=0 if 2044-X7880leftschool>25 & X7880leftschool<2014 & X7880leftschool>0
    . replace b25=0 if 2044-X7880leftschool>20 & X7880leftschool>=2014 & X7880leftschool>0
    . replace b25=0 if 2044-X7811førstebetalingsår>25 & X7811førstebetalingsår<2014 & X7880leftschool==-1
    . replace b25=0 if 2044-X7811førstebetalingsår>20 & X7811førstebetalingsår>=2014 & X7880leftschool==-1
    *år tilgivet*
    . gen b26=0

    collapse p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 p21 p22 p23 p24 p25 , by(LÅNID)



Working...
X