Good morning, if I do this, there is no error:
/* Parameters from ENUT*/
rho = 0.05/12;
h_pt = 0.2188 ;
h_ft = 0.4046 ;
hh_pt = 0.075 ;
hh_ft = 0.3574 ;
hh_om0=0;
hh_om1=0.168;
hh_pol=0;
_intord=33;
/* Initial Values */
b0 = zeros(33,1);
b0[1] = ln(0.2993 ) ; @ lam_n1 @
b0[2] = ln(0.15) ; @ lam_n2 @
b0[3] = ln(0.1179 ) ; @ lam_e1 j2j @
b0[4] = ln(0.1179 ) ; @ lam_e2 j2j @
b0[5] = ln(0.0149) ; @ eta1_pt @
b0[6] = ln(0.0149) ; @ eta1_ft @
b0[7] = ln(0.0149) ; @ eta2_pt @
b0[8] = ln(0.0149) ; @ eta2_ft @
b0[9] = 1.34 ; @ mu_wage1_pt @
b0[10] = 1.1 ; @ mu_wage1_ft @
b0[11] = ln(0.47) ; @ sigma_wage1_pt @
b0[12] = ln(0.44) ; @ sigma_wage1_ft @
b0[13] = 1.1 ; @ mu_wage2_pt @
b0[14] = 0.8 ; @ mu_wage2_ft @
b0[15] = ln(0.44) ; @ sigma_wage2_pt @
b0[16] = ln(0.6) ; @ sigma_wage2_ft @
b0[17] = ln(0.05/(1-0.05)) ; @ prob1_pt @
b0[18] = ln(0.04/(1-0.04)) ; @ prob2_pt @
b0[19] = ln(0.16/(1-0.16)) ; @ alpha1_yk@
b0[20] = ln(0.23/(1-0.23)) ; @ alpha2_yk@
b0[21] = ln(0.23/(1-0.23)) ; @ alpha3_yk@
b0[22] = ln(0.11/(1-0.11)) ; @ alpha1_nk@
b0[23] = ln(0.21/(1-0.21)) ; @ alpha2_nk@
b0[24] = ln(0.20/(1-0.20)) ; @ alpha3_nk@
b0[25] = ln(0.05/(1-0.05)) ; @ delta1 @
b0[26] = ln(0.05/(1-0.05)) ; @ delta2 @
b0[27] = ln(0.05/(1-0.05)) ; @ delta4 @
b0[28] = ln(0.9455/(1-0.9455)) ; @ gam_s1 @ // Probality of being high searching cost distribution for husbands
b0[29] = ln(0.7181/(1-0.7181)) ; @ gam_s2 @ // Probality of being high searching cost distribution for wifes
b0[30] = ln(0.01); @ gam_yk @ // Shock of receiving Kids
b0[31] = ln(0.01); @ gam_ykd @ // Shock of receiving Kids
b0[32] = ln(1.7) ; @ HH productivity high @
b0[33] = ln(0.5) ; @ HH productivity Other members @
/* Extracting Initial Values */
lam_n1 = exp(b0[1]) ;
lam_n2 = exp(b0[2]) ;
lam_e1 = exp(b0[3]) ;
lam_e2 = exp(b0[4]) ;
eta1_pt = exp(b0[5]) ;
eta1_ft = exp(b0[6]) ;
eta2_pt = exp(b0[7]) ;
eta2_ft = exp(b0[8]) ;
mu_wage1_pt = b0[9] ;
mu_wage1_ft = b0[10] ;
sigma_wage1_pt = exp(b0[11]) ;
sigma_wage1_ft = exp(b0[12]) ;
mu_wage2_pt = b0[13] ;
mu_wage2_ft = b0[14] ;
sigma_wage2_pt = exp(b0[15]) ;
sigma_wage2_ft = exp(b0[16]) ;
prob1_pt = exp(b0[17])./(1+exp(b0[17])) ;
prob2_pt = exp(b0[18])./(1+exp(b0[18])) ;
prob1_ft = 1-prob1_pt ;
prob2_ft = 1-prob2_pt ;
alpha1 = exp(b0[19])./(1+exp(b0[19])) ;
alpha2 = exp(b0[20])./(1+exp(b0[20])) ;
alpha3 = exp(b0[21])./(1+exp(b0[21])) ;
alpha1_nk = exp(b0[22])./(1+exp(b0[22])) ;
alpha2_nk = exp(b0[23])./(1+exp(b0[23])) ;
alpha3_nk = exp(b0[24])./(1+exp(b0[24])) ;
delta1 = exp(b0[25])./(1+exp(b0[25])) ;
delta2 = exp(b0[26])./(1+exp(b0[26])) ;
delta3 = delta2;
delta4 = exp(b0[27])./(1+exp(b0[27])) ;
gam_s1 = exp(b0[28])./(1+exp(b0[28])) ; @ gam_s1 @ // Probality of being high searching cost distribution for husbands
gam_s2 = exp(b0[29])./(1+exp(b0[29])) ; @ gam_s2 @ // Probality of being high searching cost distribution for wifes
gam_yk = exp(b0[30]) ; @ gam_yk @ // Shock of receiving Kids
gam_ykd = exp(b0[31]) ; @ gam_yk @ // Shock of receiving Kids
prod_h = exp(b0[32]); @ prod_h @ // Men HH productivity high
prod3 = exp(b0[33]); @ HH productivity Other members @
/* Wage Grid */
N_w = 30 ;
N_w1 = N_w ;
N_w2 = N_w ;
smallest_w1 = 1 ;
smallest_w2 = 1 ;
largest_w1 = 20 ;
largest_w2 = 20 ;
step_length_w1 = (largest_w1-smallest_w1)/N_w1 ;
step_length_w2 = (largest_w2-smallest_w2)/N_w2 ;
w1_vector = seqa(smallest_w1,step_length_w1,N_w1) ;
w2_vector = seqa(smallest_w2,step_length_w2,N_w2) ;
// Discrete distribution with low and high searching cost
s1 = h_pt ;
s2 = h_pt ;
prodM_vector = 1 | prod_h ;
prodW_vector = 1 | prod_h ;
prod1=prodM_vector[1];
prod2=prodW_vector[2];
prod3=1;
hh_om=hh_om1;
/**************************************** Utility Functions (Flow Utility) ************************/
//Define function to be minimized
//The first input is a PV structure containing the parameters
//The following arguments contain data, other than the parameters,
//which is needed by the function
proc (1) = Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1,w2,h1,h2,d_child);
local p0,hh_1,hh_2,hh_1t,hh_2t,alphaP1,alphaP2,alphaP3,alphaP1_nk,alphaP2_nk,alphaP3_nk,prod4,hh_ft2,hh_pt2,hh_om2,rHH,Utilidad;
p0 = pvUnpack(par1, "parameters");
hh_1= exp(p0[1,.])'./(1+exp(p0[1,.])') ;
hh_2= exp(p0[2,.])'./(1+exp(p0[2,.])') ;
@if rows(w1)>1 or rows(2)>2;
rHH=maxc(rows(w1)|rows(w2));
hh_1=hh_1*ones(rHH,1);
hh_2=hh_2*ones(rHH,1);
endif;@
hh_1t=hh_1./hh_pt;
hh_2t=hh_2./hh_pt;
if dHH==1;
hh_om2=hh_om1/hh_pt+hh_pol/24/hh_pt;//1.1;
prod4=prod3;
else;
hh_om2=hh_pt/hh_pt+hh_pol/24/hh_pt;
prod4=1;
endif;
if d_child==1;
alphaP1=alpha1;
alphaP2=alpha2;
alphaP3=alpha3;
else;
alphaP1=alpha1_nk;
alphaP2=alpha2_nk;
alphaP3=alpha3_nk;
endif;
if rows(w1)>1 and rows(w2)>2;
Utilidad=-((1-alphaP1-alphaP2-alphaP3)*((nonlab+w1*h1.*ones(N_w1,N_w2)+w2'*h2.*ones(N_w1,N_w2)).^delta1 - 1)/delta1
+ alphaP1*((1-sea1-hh_1-h1).^delta2 - 1)/delta2 +alphaP2*((1-sea2-hh_2-h2).^delta3 - 1)/delta3 + alphaP3*((prod1.*hh_1t.*prod2.*hh_2t.*prod4.*hh_om2).^delta4 - 1)/delta4 );
else;
Utilidad=-((1-alphaP1-alphaP2-alphaP3)*((nonlab+w1*h1+w2*h2).^delta1 - 1)/delta1
+ alphaP1*((1-sea1-hh_1-h1).^delta2 - 1)/delta2 +alphaP2*((1-sea2-hh_2-h2).^delta3 - 1)/delta3 + alphaP3*((prod1.*hh_1t.*prod2.*hh_2t.*prod4.*hh_om2).^delta4 - 1)/delta4 );
endif;
retp(Utilidad);
endp;
//It is need so leisure is >=0
proc (2) = ineqConst(struct PV par1, dHH,nonlab,sea1,sea2,w1,w2,h1,h2,d_child);
local p0,hh_1,hh_2;
p0 = pvUnpack(par1, "parameters");
hh_1= exp(p0[1])./(1+exp(p0[1])) ;
hh_2= exp(p0[2])./(1+exp(p0[2])) ;
retp( (1-sea1-hh_1-h1,1-sea2-hh_2-h2));
endp;
//Declare control structure
struct sqpSolveMTControl c0;
//Initialize structure to default values
c0 = sqpSolveMTControlCreate();
//Constrain parameters to be positive
c0.bounds = 0~1;
//Declare 'out' to be a QNewtonmtOut structure
//to hold data returned by QNewtonmt
struct sqpSolveMTout out1;
//Declare 'par' to be a Parameter Vector (PV) structure
struct PV par;
//Set PV defaults in 'par'
par = pvCreate();
//Add a variable named 'parameters' to par with a 2X1 vector of starting values
par = pvPack(par, -.3|-.3, "parameters");
//Define structure
struct Utility_Structure {
matrix U_1pt_2ue; matrix hh1_1pt_2ue; matrix hh2_1pt_2ue;
matrix U_1ft_2ue; matrix hh1_1ft_2ue; matrix hh2_1ft_2ue;
matrix U_1ue_2pt; matrix hh1_1ue_2pt; matrix hh2_1ue_2pt;
matrix U_1ue_2ft; matrix hh1_1ue_2ft; matrix hh2_1ue_2ft;
matrix U_1pt_2pt; matrix hh1_1pt_2pt; matrix hh2_1pt_2pt;
matrix U_1pt_2ft; matrix hh1_1pt_2ft; matrix hh2_1pt_2ft;
matrix U_1ft_2pt; matrix hh1_1ft_2pt; matrix hh2_1ft_2pt;
matrix U_1ft_2ft; matrix hh1_1ft_2ft; matrix hh2_1ft_2ft;
matrix U_1ue_2ue; matrix hh1_1ue_2ue; matrix hh2_1ue_2ue;
matrix U_1pt_2np; matrix hh1_1pt_2np; matrix hh2_1pt_2np;
matrix U_1ft_2np; matrix hh1_1ft_2np; matrix hh2_1ft_2np;
matrix U_1np_2pt; matrix hh1_1np_2pt; matrix hh2_1np_2pt;
matrix U_1np_2ft; matrix hh1_1np_2ft; matrix hh2_1np_2ft;
matrix U_1ue_2np; matrix hh1_1ue_2np; matrix hh2_1ue_2np;
matrix U_1np_2ue; matrix hh1_1np_2ue; matrix hh2_1np_2ue;
matrix U_1np_2np; matrix hh1_1np_2np; matrix hh2_1np_2np;
matrix U_1pt_2ue_nk; matrix hh1_1pt_2ue_nk; matrix hh2_1pt_2ue_nk;
matrix U_1ft_2ue_nk; matrix hh1_1ft_2ue_nk; matrix hh2_1ft_2ue_nk;
matrix U_1ue_2pt_nk; matrix hh1_1ue_2pt_nk; matrix hh2_1ue_2pt_nk;
matrix U_1ue_2ft_nk; matrix hh1_1ue_2ft_nk; matrix hh2_1ue_2ft_nk;
matrix U_1pt_2pt_nk; matrix hh1_1pt_2pt_nk; matrix hh2_1pt_2pt_nk;
matrix U_1pt_2ft_nk; matrix hh1_1pt_2ft_nk; matrix hh2_1pt_2ft_nk;
matrix U_1ft_2pt_nk; matrix hh1_1ft_2pt_nk; matrix hh2_1ft_2pt_nk;
matrix U_1ft_2ft_nk; matrix hh1_1ft_2ft_nk; matrix hh2_1ft_2ft_nk;
matrix U_1ue_2ue_nk; matrix hh1_1ue_2ue_nk; matrix hh2_1ue_2ue_nk;
matrix U_1pt_2np_nk; matrix hh1_1pt_2np_nk; matrix hh2_1pt_2np_nk;
matrix U_1ft_2np_nk; matrix hh1_1ft_2np_nk; matrix hh2_1ft_2np_nk;
matrix U_1np_2pt_nk; matrix hh1_1np_2pt_nk; matrix hh2_1np_2pt_nk;
matrix U_1np_2ft_nk; matrix hh1_1np_2ft_nk; matrix hh2_1np_2ft_nk;
matrix U_1ue_2np_nk; matrix hh1_1ue_2np_nk; matrix hh2_1ue_2np_nk;
matrix U_1np_2ue_nk; matrix hh1_1np_2ue_nk; matrix hh2_1np_2ue_nk;
matrix U_1np_2np_nk; matrix hh1_1np_2np_nk; matrix hh2_1np_2np_nk;
};
//Declare structure instance
struct Utility_Structure U;nonlab=1;dHH=1;
//
nonlab=1;dHH=1;
hh_M=0.77;
hh_F=0.8;prod3=0.5;
struct Utility_Structure U_Str;
//////////////////////////////////////////////kids/////////////////////////////////////////////
//1 -> Husband UE - Wife UE
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
U_Str.hh1_1ue_2ue= exp(parms[1,.])./(1+exp(parms[1,.])) ;
U_Str.hh2_1ue_2ue= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_Str.U_1ue_2ue=-out1.fct;
But what I need is define this optimization into a procedure that I need to use several times, when I define the procedure there is a mistake (G0008 : Syntax error '.par' [question.gss, line 273]):
/* Parameters from ENUT*/
rho = 0.05/12;
h_pt = 0.2188 ;
h_ft = 0.4046 ;
hh_pt = 0.075 ;
hh_ft = 0.3574 ;
hh_om0=0;
hh_om1=0.168;
hh_pol=0;
_intord=33;
/* Initial Values */
b0 = zeros(33,1);
b0[1] = ln(0.2993 ) ; @ lam_n1 @
b0[2] = ln(0.15) ; @ lam_n2 @
b0[3] = ln(0.1179 ) ; @ lam_e1 j2j @
b0[4] = ln(0.1179 ) ; @ lam_e2 j2j @
b0[5] = ln(0.0149) ; @ eta1_pt @
b0[6] = ln(0.0149) ; @ eta1_ft @
b0[7] = ln(0.0149) ; @ eta2_pt @
b0[8] = ln(0.0149) ; @ eta2_ft @
b0[9] = 1.34 ; @ mu_wage1_pt @
b0[10] = 1.1 ; @ mu_wage1_ft @
b0[11] = ln(0.47) ; @ sigma_wage1_pt @
b0[12] = ln(0.44) ; @ sigma_wage1_ft @
b0[13] = 1.1 ; @ mu_wage2_pt @
b0[14] = 0.8 ; @ mu_wage2_ft @
b0[15] = ln(0.44) ; @ sigma_wage2_pt @
b0[16] = ln(0.6) ; @ sigma_wage2_ft @
b0[17] = ln(0.05/(1-0.05)) ; @ prob1_pt @
b0[18] = ln(0.04/(1-0.04)) ; @ prob2_pt @
b0[19] = ln(0.16/(1-0.16)) ; @ alpha1_yk@
b0[20] = ln(0.23/(1-0.23)) ; @ alpha2_yk@
b0[21] = ln(0.23/(1-0.23)) ; @ alpha3_yk@
b0[22] = ln(0.11/(1-0.11)) ; @ alpha1_nk@
b0[23] = ln(0.21/(1-0.21)) ; @ alpha2_nk@
b0[24] = ln(0.20/(1-0.20)) ; @ alpha3_nk@
b0[25] = ln(0.05/(1-0.05)) ; @ delta1 @
b0[26] = ln(0.05/(1-0.05)) ; @ delta2 @
b0[27] = ln(0.05/(1-0.05)) ; @ delta4 @
b0[28] = ln(0.9455/(1-0.9455)) ; @ gam_s1 @ // Probality of being high searching cost distribution for husbands
b0[29] = ln(0.7181/(1-0.7181)) ; @ gam_s2 @ // Probality of being high searching cost distribution for wifes
b0[30] = ln(0.01); @ gam_yk @ // Shock of receiving Kids
b0[31] = ln(0.01); @ gam_ykd @ // Shock of receiving Kids
b0[32] = ln(1.7) ; @ HH productivity high @
b0[33] = ln(0.5) ; @ HH productivity Other members @
/* Extracting Initial Values */
lam_n1 = exp(b0[1]) ;
lam_n2 = exp(b0[2]) ;
lam_e1 = exp(b0[3]) ;
lam_e2 = exp(b0[4]) ;
eta1_pt = exp(b0[5]) ;
eta1_ft = exp(b0[6]) ;
eta2_pt = exp(b0[7]) ;
eta2_ft = exp(b0[8]) ;
mu_wage1_pt = b0[9] ;
mu_wage1_ft = b0[10] ;
sigma_wage1_pt = exp(b0[11]) ;
sigma_wage1_ft = exp(b0[12]) ;
mu_wage2_pt = b0[13] ;
mu_wage2_ft = b0[14] ;
sigma_wage2_pt = exp(b0[15]) ;
sigma_wage2_ft = exp(b0[16]) ;
prob1_pt = exp(b0[17])./(1+exp(b0[17])) ;
prob2_pt = exp(b0[18])./(1+exp(b0[18])) ;
prob1_ft = 1-prob1_pt ;
prob2_ft = 1-prob2_pt ;
alpha1 = exp(b0[19])./(1+exp(b0[19])) ;
alpha2 = exp(b0[20])./(1+exp(b0[20])) ;
alpha3 = exp(b0[21])./(1+exp(b0[21])) ;
alpha1_nk = exp(b0[22])./(1+exp(b0[22])) ;
alpha2_nk = exp(b0[23])./(1+exp(b0[23])) ;
alpha3_nk = exp(b0[24])./(1+exp(b0[24])) ;
delta1 = exp(b0[25])./(1+exp(b0[25])) ;
delta2 = exp(b0[26])./(1+exp(b0[26])) ;
delta3 = delta2;
delta4 = exp(b0[27])./(1+exp(b0[27])) ;
gam_s1 = exp(b0[28])./(1+exp(b0[28])) ; @ gam_s1 @ // Probality of being high searching cost distribution for husbands
gam_s2 = exp(b0[29])./(1+exp(b0[29])) ; @ gam_s2 @ // Probality of being high searching cost distribution for wifes
gam_yk = exp(b0[30]) ; @ gam_yk @ // Shock of receiving Kids
gam_ykd = exp(b0[31]) ; @ gam_yk @ // Shock of receiving Kids
prod_h = exp(b0[32]); @ prod_h @ // Men HH productivity high
prod3 = exp(b0[33]); @ HH productivity Other members @
/* Wage Grid */
N_w = 30 ;
N_w1 = N_w ;
N_w2 = N_w ;
smallest_w1 = 1 ;
smallest_w2 = 1 ;
largest_w1 = 20 ;
largest_w2 = 20 ;
step_length_w1 = (largest_w1-smallest_w1)/N_w1 ;
step_length_w2 = (largest_w2-smallest_w2)/N_w2 ;
w1_vector = seqa(smallest_w1,step_length_w1,N_w1) ;
w2_vector = seqa(smallest_w2,step_length_w2,N_w2) ;
// Discrete distribution with low and high searching cost
s1 = h_pt ;
s2 = h_pt ;
prodM_vector = 1 | prod_h ;
prodW_vector = 1 | prod_h ;
prod1=prodM_vector[1];
prod2=prodW_vector[2];
prod3=1;
hh_om=hh_om1;
/**************************************** Utility Functions (Flow Utility) ************************/
//Define function to be minimized
//The first input is a PV structure containing the parameters
//The following arguments contain data, other than the parameters,
//which is needed by the function
proc (1) = Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1,w2,h1,h2,d_child);
local p0,hh_1,hh_2,hh_1t,hh_2t,alphaP1,alphaP2,alphaP3,alphaP1_nk,alphaP2_nk,alphaP3_nk,prod4,hh_ft2,hh_pt2,hh_om2,rHH,Utilidad;
p0 = pvUnpack(par1, "parameters");
hh_1= exp(p0[1,.])'./(1+exp(p0[1,.])') ;
hh_2= exp(p0[2,.])'./(1+exp(p0[2,.])') ;
@if rows(w1)>1 or rows(2)>2;
rHH=maxc(rows(w1)|rows(w2));
hh_1=hh_1*ones(rHH,1);
hh_2=hh_2*ones(rHH,1);
endif;@
hh_1t=hh_1./hh_pt;
hh_2t=hh_2./hh_pt;
if dHH==1;
hh_om2=hh_om1/hh_pt+hh_pol/24/hh_pt;//1.1;
prod4=prod3;
else;
hh_om2=hh_pt/hh_pt+hh_pol/24/hh_pt;
prod4=1;
endif;
if d_child==1;
alphaP1=alpha1;
alphaP2=alpha2;
alphaP3=alpha3;
else;
alphaP1=alpha1_nk;
alphaP2=alpha2_nk;
alphaP3=alpha3_nk;
endif;
if rows(w1)>1 and rows(w2)>2;
Utilidad=-((1-alphaP1-alphaP2-alphaP3)*((nonlab+w1*h1.*ones(N_w1,N_w2)+w2'*h2.*ones(N_w1,N_w2)).^delta1 - 1)/delta1
+ alphaP1*((1-sea1-hh_1-h1).^delta2 - 1)/delta2 +alphaP2*((1-sea2-hh_2-h2).^delta3 - 1)/delta3 + alphaP3*((prod1.*hh_1t.*prod2.*hh_2t.*prod4.*hh_om2).^delta4 - 1)/delta4 );
else;
Utilidad=-((1-alphaP1-alphaP2-alphaP3)*((nonlab+w1*h1+w2*h2).^delta1 - 1)/delta1
+ alphaP1*((1-sea1-hh_1-h1).^delta2 - 1)/delta2 +alphaP2*((1-sea2-hh_2-h2).^delta3 - 1)/delta3 + alphaP3*((prod1.*hh_1t.*prod2.*hh_2t.*prod4.*hh_om2).^delta4 - 1)/delta4 );
endif;
retp(Utilidad);
endp;
//It is need so leisure is >=0
proc (2) = ineqConst(struct PV par1, dHH,nonlab,sea1,sea2,w1,w2,h1,h2,d_child);
local p0,hh_1,hh_2;
p0 = pvUnpack(par1, "parameters");
hh_1= exp(p0[1])./(1+exp(p0[1])) ;
hh_2= exp(p0[2])./(1+exp(p0[2])) ;
retp( (1-sea1-hh_1-h1,1-sea2-hh_2-h2));
endp;
//Declare control structure
struct sqpSolveMTControl c0;
//Initialize structure to default values
c0 = sqpSolveMTControlCreate();
//Constrain parameters to be positive
c0.bounds = 0~1;
//Declare 'out' to be a QNewtonmtOut structure
//to hold data returned by QNewtonmt
struct sqpSolveMTout out1;
//Declare 'par' to be a Parameter Vector (PV) structure
struct PV par;
//Set PV defaults in 'par'
par = pvCreate();
//Add a variable named 'parameters' to par with a 2X1 vector of starting values
par = pvPack(par, -.3|-.3, "parameters");
//Define structure
struct Utility_Structure {
matrix U_1pt_2ue; matrix hh1_1pt_2ue; matrix hh2_1pt_2ue;
matrix U_1ft_2ue; matrix hh1_1ft_2ue; matrix hh2_1ft_2ue;
matrix U_1ue_2pt; matrix hh1_1ue_2pt; matrix hh2_1ue_2pt;
matrix U_1ue_2ft; matrix hh1_1ue_2ft; matrix hh2_1ue_2ft;
matrix U_1pt_2pt; matrix hh1_1pt_2pt; matrix hh2_1pt_2pt;
matrix U_1pt_2ft; matrix hh1_1pt_2ft; matrix hh2_1pt_2ft;
matrix U_1ft_2pt; matrix hh1_1ft_2pt; matrix hh2_1ft_2pt;
matrix U_1ft_2ft; matrix hh1_1ft_2ft; matrix hh2_1ft_2ft;
matrix U_1ue_2ue; matrix hh1_1ue_2ue; matrix hh2_1ue_2ue;
matrix U_1pt_2np; matrix hh1_1pt_2np; matrix hh2_1pt_2np;
matrix U_1ft_2np; matrix hh1_1ft_2np; matrix hh2_1ft_2np;
matrix U_1np_2pt; matrix hh1_1np_2pt; matrix hh2_1np_2pt;
matrix U_1np_2ft; matrix hh1_1np_2ft; matrix hh2_1np_2ft;
matrix U_1ue_2np; matrix hh1_1ue_2np; matrix hh2_1ue_2np;
matrix U_1np_2ue; matrix hh1_1np_2ue; matrix hh2_1np_2ue;
matrix U_1np_2np; matrix hh1_1np_2np; matrix hh2_1np_2np;
matrix U_1pt_2ue_nk; matrix hh1_1pt_2ue_nk; matrix hh2_1pt_2ue_nk;
matrix U_1ft_2ue_nk; matrix hh1_1ft_2ue_nk; matrix hh2_1ft_2ue_nk;
matrix U_1ue_2pt_nk; matrix hh1_1ue_2pt_nk; matrix hh2_1ue_2pt_nk;
matrix U_1ue_2ft_nk; matrix hh1_1ue_2ft_nk; matrix hh2_1ue_2ft_nk;
matrix U_1pt_2pt_nk; matrix hh1_1pt_2pt_nk; matrix hh2_1pt_2pt_nk;
matrix U_1pt_2ft_nk; matrix hh1_1pt_2ft_nk; matrix hh2_1pt_2ft_nk;
matrix U_1ft_2pt_nk; matrix hh1_1ft_2pt_nk; matrix hh2_1ft_2pt_nk;
matrix U_1ft_2ft_nk; matrix hh1_1ft_2ft_nk; matrix hh2_1ft_2ft_nk;
matrix U_1ue_2ue_nk; matrix hh1_1ue_2ue_nk; matrix hh2_1ue_2ue_nk;
matrix U_1pt_2np_nk; matrix hh1_1pt_2np_nk; matrix hh2_1pt_2np_nk;
matrix U_1ft_2np_nk; matrix hh1_1ft_2np_nk; matrix hh2_1ft_2np_nk;
matrix U_1np_2pt_nk; matrix hh1_1np_2pt_nk; matrix hh2_1np_2pt_nk;
matrix U_1np_2ft_nk; matrix hh1_1np_2ft_nk; matrix hh2_1np_2ft_nk;
matrix U_1ue_2np_nk; matrix hh1_1ue_2np_nk; matrix hh2_1ue_2np_nk;
matrix U_1np_2ue_nk; matrix hh1_1np_2ue_nk; matrix hh2_1np_2ue_nk;
matrix U_1np_2np_nk; matrix hh1_1np_2np_nk; matrix hh2_1np_2np_nk;
};
//Declare structure instance
struct Utility_Structure U;nonlab=1;dHH=1;
//
nonlab=1;dHH=1;
hh_M=0.77;
hh_F=0.8;prod3=0.5;
proc (1) = hh_utility(nonlab,dHH) ;
local alphaP1,alphaP2,alphaP3,alphaP1_nk,alphaP2_nk,alphaP3_nk,prod4,hh_ft2,hh_pt2,hh_om2,hh_1v,hh_2v,parms,out1,
hh_1v1,hh_1v2,hh_1v3,hh_1v4,hh_1v5,hh_1v6,hh_1v7,hh_1v8,hh_2v1,hh_2v2,hh_2v3,hh_2v4,hh_2v5,hh_2v6,hh_2v7,hh_2v8,
hh_1m1,hh_1m2,hh_1m3,hh_1m4,hh_1m5,hh_1m6,hh_1m7,hh_1m8,hh_2m1,hh_2m2,hh_2m3,hh_2m4,hh_2m5,hh_2m6,hh_2m7,hh_2m8,
U_v1,U_v2,U_v3,U_v4,U_v5,U_v6,U_v7,U_v8,U_m1,U_m2,U_m3,U_m4,U_m5,U_m6,U_m7,U_m8;
hh_ft2=hh_ft/hh_pt;
hh_pt2=hh_pt/hh_pt;
if dHH==1;
hh_om2=hh_om1/hh_pt;
prod4=prod3;
else;
hh_om2=hh_pt/hh_pt;
prod4=1;
endif;
hh_1v1=zeros(N_w1,1);
hh_2v1=zeros(N_w2,1);
hh_1m1=zeros(N_w1,N_w2);
hh_2m1=zeros(N_w1,N_w2);
U_v1=zeros(N_w1,1);
U_m1=zeros(N_w1,N_w2);
hh_1v2=hh_1v1;hh_1v3=hh_1v1;hh_1v4=hh_1v1;hh_1v5=hh_1v1;hh_1v6=hh_1v1;hh_1v7=hh_1v1;hh_1v8=hh_1v1;
hh_2v2=hh_2v1;hh_2v3=hh_2v1;hh_2v4=hh_2v1;hh_2v5=hh_2v1;hh_2v6=hh_2v1;hh_2v7=hh_2v1;hh_2v8=hh_2v1;
hh_1m2=hh_1m1;hh_1m3=hh_1m1;hh_1m4=hh_1m1;hh_1m5=hh_1m1;hh_1m6=hh_1m1;hh_1m7=hh_1m1;hh_1m8=hh_1m1;
hh_2m2=hh_2m1;hh_2m3=hh_2m1;hh_2m4=hh_2m1;hh_2m5=hh_2m1;hh_2m6=hh_2m1;hh_2m7=hh_2m1;hh_2m8=hh_2m1;
U_v2=U_v1;U_v3=U_v1;U_v4=U_v1;U_v5=U_v1;U_v6=U_v1;U_v7=U_v1;U_v8=U_v1;
U_m2=U_m1;U_m3=U_m1;U_m4=U_m1;
print "utility" s1 s2 hh_om2;
print hh_pt2 hh_ft2 hh_om2 prod1 prod2 prod4 prod1.*hh_1v.*prod2.*hh_2v.*prod4.*hh_om2;
// Declare Structure
struct Utility_Structure U_Str;
//////////////////////////////////////////////kids/////////////////////////////////////////////
//1 -> Husband UE - Wife UE
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
U_Str.hh1_1ue_2ue= exp(parms[1,.])./(1+exp(parms[1,.])) ;
U_Str.hh2_1ue_2ue= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_Str.U_1ue_2ue=-out1.fct;
//Util_func1(U_Str.hh1_1ue_2ue,U_Str.hh2_1ue_2ue,dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
@ //14-> Husband UE - Wife OLF
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,0 ,0,0,0,0, 1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
U_Str.hh1_1ue_2np= exp(parms[1,.])./(1+exp(parms[1,.])) ;
U_Str.hh2_1ue_2np= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_Str.U_1ue_2np=-out1.fct;
//15-> Husband OLF - Wife UE
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,0 ,s2 ,0,0,0,0, 1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
U_Str.hh1_1np_2ue= exp(parms[1,.])./(1+exp(parms[1,.])) ;
U_Str.hh2_1np_2ue= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_Str.U_1np_2ue=-out1.fct;
//16-> Husband OLF - Wife OLF (NP)
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,0,0 ,0,0,0,0, 1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
U_Str.hh1_1np_2np= exp(parms[1,.])./(1+exp(parms[1,.])) ;
U_Str.hh2_1np_2np= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_Str.U_1np_2np=-out1.fct;
for i (1,N_w,1);
//2 -> Husband PT - Wife UE
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,0 , s2 ,w1_vector[i],0,h_pt,0,1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v1[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v1[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v1[i]=-out1.fct;
//3 -> Husband FT - Wife UE
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,0 ,s2,w1_vector[i],0,h_ft,0,1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v2[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v2[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v2[i]=-out1.fct;
//10 -> Husband PT - Wife NP
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,0 , 0 ,w1_vector[i],0,h_pt,0,1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v3[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v3[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v3[i]=-out1.fct;
//11 -> Husband FT - Wife NP
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab ,0 , 0,w1_vector[i],0,h_ft,0,1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v4[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v4[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v4[i]=-out1.fct;
for j (1,N_w,1);
//6 -> Husband PT - Wife PT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab ,0, 0 ,w1_vector[i],w2_vector[j],h_pt,h_pt,1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1m1[i,j]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2m1[i,j]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_m1[i,j]=-out1.fct;
//7 -> Husband FT - Wife PT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,0, s2 ,w1_vector[i],w2_vector[j],h_ft,h_pt,1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1m2[i,j]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2m2[i,j]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_m2[i,j]=-out1.fct;
//8 -> Husband PT - Wife FT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab ,0, 0 ,w1_vector[i],w2_vector[j],h_pt,h_ft,1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1m3[i,j]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2m3[i,j]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_m3[i,j]=-out1.fct;
//9 -> Husband FT - Wife FT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab ,0, 0 ,w1_vector[i],w2_vector[j],h_ft,h_ft,1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1m4[i,j]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2m4[i,j]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_m4[i,j]=-out1.fct;
endfor; //for j
endfor; //for i
for i (1,N_w,1);
//4 -> Husband UE - Wife PT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2 ,w1,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,s1, 0 ,0,w2_vector[i],0,h_pt,1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v5[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v5[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v5[i]=-out1.fct;
//5 -> Husband UE - Wife FT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2 ,w1,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,s1, 0 ,0,w2_vector[i],0,h_ft,1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v6[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v6[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v6[i]=-out1.fct;
//12-> Husband OLF - Wife PT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2 ,w1,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,0 ,0 ,0,w2_vector[i],0,h_pt,1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v7[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v7[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v7[i]=-out1.fct;
//13-> Husband OLF - Wife FT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2 ,w1,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,0 ,0 ,0,w2_vector[i],0,h_ft,1);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v8[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v8[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v8[i]=-out1.fct;
endfor; //for i
//2 -> Husband PT - Wife UE
U_Str.hh1_1pt_2ue=hh_1v1;
U_Str.hh2_1pt_2ue=hh_2v1;
U_Str.U_1pt_2ue = U_v1;
//3 -> Husband FT - Wife UE
U_Str.hh1_1ft_2ue=hh_1v2;
U_Str.hh2_1ft_2ue=hh_2v2;
U_Str.U_1ft_2ue = U_v2;
//10 -> Husband PT - Wife NP
U_Str.hh1_1pt_2np=hh_1v3;
U_Str.hh2_1pt_2np=hh_2v3;
U_Str.U_1pt_2np = U_v3;
//11 -> Husband FT - Wife NP
U_Str.hh1_1ft_2np=hh_1v4;
U_Str.hh2_1ft_2np=hh_2v4;
U_Str.U_1ft_2np = U_v4;
//4 -> Husband UE - Wife PT
U_Str.hh1_1ue_2pt=hh_1v5;
U_Str.hh2_1ue_2pt=hh_2v5;
U_Str.U_1ue_2pt = U_v5;
//5 -> Husband UE - Wife FT
U_Str.hh1_1ue_2ft=hh_1v6;
U_Str.hh2_1ue_2ft=hh_2v6;
U_Str.U_1ue_2ft = U_v6;
//12-> Husband OLF - Wife PT
U_Str.hh1_1np_2pt=hh_1v7;
U_Str.hh2_1np_2pt=hh_2v7;
U_Str.U_1np_2pt = U_v7;
//13-> Husband OLF - Wife FT
U_Str.hh1_1np_2ft=hh_1v8;
U_Str.hh2_1np_2ft=hh_2v8;
U_Str.U_1np_2ft = U_v8;
//6 -> Husband PT - Wife PT
U_Str.hh1_1pt_2pt=hh_1m1;
U_Str.hh2_1pt_2pt=hh_2m1;
U_Str.U_1pt_2pt = U_m1;
//7 -> Husband FT - Wife PT
U_Str.hh1_1ft_2pt=hh_1m2;
U_Str.hh2_1ft_2pt=hh_2m2;
U_Str.U_1ft_2pt = U_m2;
//8 -> Husband PT - Wife FT
U_Str.hh1_1pt_2ft=hh_1m3;
U_Str.hh2_1pt_2ft=hh_2m3;
U_Str.U_1pt_2ft = U_m3;
//9 -> Husband FT - Wife FT
U_Str.hh1_1ft_2ft=hh_1m4;
U_Str.hh2_1ft_2ft=hh_2m4;
U_Str.U_1ft_2ft = U_m4;
//////////////////////////////////////////////no kids/////////////////////////////////////////////
//1 -> Husband UE - Wife UE
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
U_Str.hh1_1ue_2ue_nk= exp(parms[1,.])./(1+exp(parms[1,.])) ;
U_Str.hh2_1ue_2ue_nk= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_Str.U_1ue_2ue_nk=-out1.fct;
//Util_func1(U_Str.hh1_1ue_2ue_nk,U_Str.hh2_1ue_2ue_nk,dHH,nonlab,s1 ,s2 ,0,0,0,0, 0);
//14-> Husband UE - Wife OLF
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,0 ,0,0,0,0, 0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
U_Str.hh1_1ue_2np_nk= exp(parms[1,.])./(1+exp(parms[1,.])) ;
U_Str.hh2_1ue_2np_nk= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_Str.U_1ue_2np_nk=-out1.fct;
//15-> Husband OLF - Wife UE
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,0 ,s2 ,0,0,0,0, 0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
U_Str.hh1_1np_2ue_nk= exp(parms[1,.])./(1+exp(parms[1,.])) ;
U_Str.hh2_1np_2ue_nk= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_Str.U_1np_2ue_nk=-out1.fct;
//16-> Husband OLF - Wife OLF (NP)
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,0,0 ,0,0,0,0, 0);
//Get returned parameters from the output structure and Print returned parameters and Utility
for i (1,N_w,1);
//2 -> Husband PT - Wife UE
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,0 , s2 ,w1_vector[i],0,h_pt,0,0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v1[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v1[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v1[i]=-out1.fct;
//3 -> Husband FT - Wife UE
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,0 ,s2,w1_vector[i],0,h_ft,0,0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v2[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v2[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v2[i]=-out1.fct;
//10 -> Husband PT - Wife NP
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,0 , 0 ,w1_vector[i],0,h_pt,0,0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v3[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v3[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v3[i]=-out1.fct;
//11 -> Husband FT - Wife NP
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab ,0 , 0,w1_vector[i],0,h_ft,0,0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v4[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v4[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v4[i]=-out1.fct;
for j (1,N_w,1);
//6 -> Husband PT - Wife PT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab ,0, 0 ,w1_vector[i],w2_vector[j],h_pt,h_pt,0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1m1[i,j]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2m1[i,j]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_m1[i,j]=-out1.fct;
//7 -> Husband FT - Wife PT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,0, s2 ,w1_vector[i],w2_vector[j],h_ft,h_pt,0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1m2[i,j]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2m2[i,j]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_m2[i,j]=-out1.fct;
//8 -> Husband PT - Wife FT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab ,0, 0 ,w1_vector[i],w2_vector[j],h_pt,h_ft,0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1m3[i,j]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2m3[i,j]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_m3[i,j]=-out1.fct;
//9 -> Husband FT - Wife FT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2,w1 ,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab ,0, 0 ,w1_vector[i],w2_vector[j],h_ft,h_ft,0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1m4[i,j]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2m4[i,j]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_m4[i,j]=-out1.fct;
endfor; //for j
endfor; //for i
for i (1,N_w,1);
//4 -> Husband UE - Wife PT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2 ,w1,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,s1, 0 ,0,w2_vector[i],0,h_pt,0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v5[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v5[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v5[i]=-out1.fct;
//5 -> Husband UE - Wife FT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2 ,w1,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,s1, 0 ,0,w2_vector[i],0,h_ft,0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v6[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v6[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v6[i]=-out1.fct;
//12-> Husband OLF - Wife PT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2 ,w1,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,0 ,0 ,0,w2_vector[i],0,h_pt,0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v7[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v7[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v7[i]=-out1.fct;
//13-> Husband OLF - Wife FT
// Util_func(struct PV par1, dHH,nonlab,sea1,sea2 ,w1,w2 ,h1,h2,d_child);
out1 = sqpSolveMT(&Util_func,par,dHH,nonlab,0 ,0 ,0,w2_vector[i],0,h_ft,0);
//Get returned parameters from the output structure and Print returned parameters and Utility
parms = pvGetParVector(out1.par);
hh_1v8[i]= exp(parms[1,.])./(1+exp(parms[1,.])) ;
hh_2v8[i]= exp(parms[2,.])./(1+exp(parms[2,.])) ;
U_v8[i]=-out1.fct;
endfor; //for i
//2 -> Husband PT - Wife UE
U_Str.hh1_1pt_2ue_nk=hh_1v1;
U_Str.hh2_1pt_2ue_nk=hh_2v1;
U_Str.U_1pt_2ue_nk = U_v1;
//3 -> Husband FT - Wife UE
U_Str.hh1_1ft_2ue_nk=hh_1v2;
U_Str.hh2_1ft_2ue_nk=hh_2v2;
U_Str.U_1ft_2ue_nk = U_v2;
//10 -> Husband PT - Wife NP
U_Str.hh1_1pt_2np_nk=hh_1v3;
U_Str.hh2_1pt_2np_nk=hh_2v3;
U_Str.U_1pt_2np_nk = U_v3;
//11 -> Husband FT - Wife NP
U_Str.hh1_1ft_2np_nk=hh_1v4;
U_Str.hh2_1ft_2np_nk=hh_2v4;
U_Str.U_1ft_2np_nk = U_v4;
//4 -> Husband UE - Wife PT
U_Str.hh1_1ue_2pt_nk=hh_1v5;
U_Str.hh2_1ue_2pt_nk=hh_2v5;
U_Str.U_1ue_2pt_nk = U_v5;
//5 -> Husband UE - Wife FT
U_Str.hh1_1ue_2ft_nk=hh_1v6;
U_Str.hh2_1ue_2ft_nk=hh_2v6;
U_Str.U_1ue_2ft_nk = U_v6;
//12-> Husband OLF - Wife PT
U_Str.hh1_1np_2pt_nk=hh_1v7;
U_Str.hh2_1np_2pt_nk=hh_2v7;
U_Str.U_1np_2pt_nk = U_v7;
//13-> Husband OLF - Wife FT
U_Str.hh1_1np_2ft_nk=hh_1v8;
U_Str.hh2_1np_2ft_nk=hh_2v8;
U_Str.U_1np_2ft_nk = U_v8;
//6 -> Husband PT - Wife PT
U_Str.hh1_1pt_2pt_nk=hh_1m1;
U_Str.hh2_1pt_2pt_nk=hh_2m1;
U_Str.U_1pt_2pt_nk = U_m1;
//7 -> Husband FT - Wife PT
U_Str.hh1_1ft_2pt_nk=hh_1m2;
U_Str.hh2_1ft_2pt_nk=hh_2m2;
U_Str.U_1ft_2pt_nk = U_m2;
//8 -> Husband PT - Wife FT
U_Str.hh1_1pt_2ft_nk=hh_1m3;
U_Str.hh2_1pt_2ft_nk=hh_2m3;
U_Str.U_1pt_2ft_nk = U_m3;
//9 -> Husband FT - Wife FT
U_Str.hh1_1ft_2ft_nk=hh_1m4;
U_Str.hh2_1ft_2ft_nk=hh_2m4;
U_Str.U_1ft_2ft_nk = U_m4;
// Output
@ retp(U_Str);
endp;
I think that I need to define something in the hh_utility procedure, something as:
proc (1) = hh_utility(struct PV par, nonlab,dHH) ;
But I can't make it work, can you help me with this.
3 Answers
0
The problem is that when out1
is added to the local variable list of the procedure hh_utility
, that tells GAUSS that it will be a weakly typed variable. A weakly typed variable is one whose type is allowed to change, such as matrices and strings.
// Create a matrix
my_mat = { 1 2 3 };
// Since it is weakly typed, we can make
// it a different type, for example a string
my_mat = "my_mat is now equal to this string!";
// Declare a structure
struct sqpsolvemtOut out;
// Try to make 'out' a string, but fail with error
out = "this assignment will fail, because structs cannot change types";
So what you need to do to resolve the problem is:
- Remove
out
from thehh_utility
local variable list. - Declare
out
to be ansqpsolvemtOut
structure.
Here is an abbreviated example:
// WRONG!!
proc (1) = hh_utility(nonlab,dHH);
local alphaP1,alphaP2,alphaP3,out1;
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
// CORRECT!!
proc (1) = hh_utility(nonlab,dHH);
local alphaP1,alphaP2,alphaP3;
// Declare 'out1' to be an sqpSovlveMTOut structure
// Since the declaration is inside a proc, the
// 'out1' structure will be a local variable
struct sqpSolveMTOut out1;
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
0
Sweet!!! Now is working and all my current problems are solved!
CAn you expand the explanation of the declaration of the struct into the procedure (I totally got the local explanation).
proc (1) = hh_utility(nonlab,dHH); local alphaP1,alphaP2,alphaP3;
// Declare 'out1' to be an sqpSovlveMTOut structure
// Since the declaration is inside a proc, the
// 'out1' structure will be a local variable
struct sqpSolveMTOut out1;
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
In my initial code this line was out, so I though that this was a global. Thank you again!
//Declare 'out' to be a QNewtonmtOut structure
//to hold data returned by QNewtonmt
struct sqpSolveMTout out1;
0
Let's look at three situations. We'll start with the situation you were having trouble with which was equivalent to this snippet:
Snippet 1
// Declare a global struct
struct sqpSolvemtOut out1;
proc (1) = hh_utility(nonlab, dHH);
// Placing 'out1' in the local list
// makes any reference to a variable 'out1'
// inside this procedure to be a matrix, array or string
local alphaP1, alphaP1, out1;
// Will cause error on this assignment, since local 'out1'
// is not an 'sqpSolvemtOut' structure
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
As the comments above indicate, yes the code did have a global variable out1
which was a sqpSolvemtOut
structure. However, the local declaration of out1
makes any usage of out1
inside of hh_utility
to refer to the local out1
. Since it is declared in the local
list, it can only be a weakly typed variable, such as matrix, array or string.
Snippet 2
Below is what we recommended in the earlier post.
// Declare a global struct
struct sqpSolvemtOut out1;
proc (1) = hh_utility(nonlab, dHH);
local alphaP1, alphaP1;
// Declare to be a LOCAL sqpSolvemtOut struct
struct sqpSolvemtOut out1;
// Use the local 'out1'. No problems.
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
In the situation above, there are two different sqpSolvemtOut
structures named out1
. There is a global out1
AND an out1
which is local to the procedure hh_utility
.
Snippet 3
Here is another alternative which I think will make all of this clear. We could have just taken out1
from the hh_utility
local list and NOT declared a local version like this:
// Declare a global struct
struct sqpSolvemtOut out1;
proc (1) = hh_utility(nonlab, dHH);
local alphaP1, alphaP1;
// Declare to be a LOCAL sqpSolvemtOut struct
struct sqpSolvemtOut out1;
// Use the GLOBAL 'out1' declared above
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
This final version would work since the global out1
structure exists and would be available. However, it is not recommended. Global variables should be used sparingly and it is generally best to avoid assigning to global variables.
Your Answer
3 Answers
The problem is that when out1
is added to the local variable list of the procedure hh_utility
, that tells GAUSS that it will be a weakly typed variable. A weakly typed variable is one whose type is allowed to change, such as matrices and strings.
// Create a matrix
my_mat = { 1 2 3 };
// Since it is weakly typed, we can make
// it a different type, for example a string
my_mat = "my_mat is now equal to this string!";
// Declare a structure
struct sqpsolvemtOut out;
// Try to make 'out' a string, but fail with error
out = "this assignment will fail, because structs cannot change types";
So what you need to do to resolve the problem is:
- Remove
out
from thehh_utility
local variable list. - Declare
out
to be ansqpsolvemtOut
structure.
Here is an abbreviated example:
// WRONG!!
proc (1) = hh_utility(nonlab,dHH);
local alphaP1,alphaP2,alphaP3,out1;
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
// CORRECT!!
proc (1) = hh_utility(nonlab,dHH);
local alphaP1,alphaP2,alphaP3;
// Declare 'out1' to be an sqpSovlveMTOut structure
// Since the declaration is inside a proc, the
// 'out1' structure will be a local variable
struct sqpSolveMTOut out1;
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
Sweet!!! Now is working and all my current problems are solved!
CAn you expand the explanation of the declaration of the struct into the procedure (I totally got the local explanation).
proc (1) = hh_utility(nonlab,dHH); local alphaP1,alphaP2,alphaP3;
// Declare 'out1' to be an sqpSovlveMTOut structure
// Since the declaration is inside a proc, the
// 'out1' structure will be a local variable
struct sqpSolveMTOut out1;
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
In my initial code this line was out, so I though that this was a global. Thank you again!
//Declare 'out' to be a QNewtonmtOut structure
//to hold data returned by QNewtonmt
struct sqpSolveMTout out1;
Let's look at three situations. We'll start with the situation you were having trouble with which was equivalent to this snippet:
Snippet 1
// Declare a global struct
struct sqpSolvemtOut out1;
proc (1) = hh_utility(nonlab, dHH);
// Placing 'out1' in the local list
// makes any reference to a variable 'out1'
// inside this procedure to be a matrix, array or string
local alphaP1, alphaP1, out1;
// Will cause error on this assignment, since local 'out1'
// is not an 'sqpSolvemtOut' structure
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
As the comments above indicate, yes the code did have a global variable out1
which was a sqpSolvemtOut
structure. However, the local declaration of out1
makes any usage of out1
inside of hh_utility
to refer to the local out1
. Since it is declared in the local
list, it can only be a weakly typed variable, such as matrix, array or string.
Snippet 2 Below is what we recommended in the earlier post.
// Declare a global struct
struct sqpSolvemtOut out1;
proc (1) = hh_utility(nonlab, dHH);
local alphaP1, alphaP1;
// Declare to be a LOCAL sqpSolvemtOut struct
struct sqpSolvemtOut out1;
// Use the local 'out1'. No problems.
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
In the situation above, there are two different sqpSolvemtOut
structures named out1
. There is a global out1
AND an out1
which is local to the procedure hh_utility
.
Snippet 3
Here is another alternative which I think will make all of this clear. We could have just taken out1
from the hh_utility
local list and NOT declared a local version like this:
// Declare a global struct
struct sqpSolvemtOut out1;
proc (1) = hh_utility(nonlab, dHH);
local alphaP1, alphaP1;
// Declare to be a LOCAL sqpSolvemtOut struct
struct sqpSolvemtOut out1;
// Use the GLOBAL 'out1' declared above
out1 = sqpSolveMT(&Util_func,par, dHH,nonlab,s1 ,s2 ,0,0,0,0, 1);
This final version would work since the global out1
structure exists and would be available. However, it is not recommended. Global variables should be used sparingly and it is generally best to avoid assigning to global variables.