var 
    v_K,                        /* Kapital */
    v_C,                        /* Consumption */
    v_Lambda_z,                 /* Utility */
    v_Return_Domestic,          /* Domestic interest rate */
    v_I,                        /* Investment */
    v_Q,                        /* Marginal utility of capital */
    v_Wage_Households,          /* Wage households */
    v_Return_Kapital,           /* Return on Kapital */
    v_Aggregated_Domestic_Good,
    v_L,                        /* Labor */
    v_Imports,
    v_Exports,
    v_Debt,                     /* Debt of the government */
    v_Bond_Foreign,             /* Foreign Bond */
    v_GDP,
    v_Inflation_Domestic_Good,  /* Inflation for domestic goods */
    v_Inflation_Import_Good,    /* Inflation for import goods */
    v_Inflation_Consumption,     /* Inflation for consumption */
    v_Inflation_Invest,
    v_Inflation_Government,
    v_Inflation_Export,
    v_Inflation,                /* Inflation rate */
    v_AggregatedPrice,
    v_Price_Domestic_Good,
    v_Price_Import_Good,
    v_Price_Investment_Good,
    v_Gov_Good_Price,
    v_Price_Export_Good,
    v_Price_Imported_Good_Foreign,
    v_Consumption_Price,

    /* SHOCKS */
    SHOCK_eps_i,                 /* Investment shock */
    SHOCK_eps_c,                 /* Consumption shock*/
    SHOCK_eps_phi,               /* UIP shock*/
    SHOCK_eps_l,                /* Labor shock */
    SHOCK_domestic_technology,   /* Domestic stationary technology shock*/                     
    SHOCK_Inflation_Domestic_Good,
    SHOCK_Inflation_Import_Good,
    SHOCK_Inflation_Consumption, /* Shock to inflation consumption */
    SHOCK_Inflation_Investment,
    SHOCK_Inflation_Government,
    SHOCK_Inflation_Export,

    SHOCK_Zeta,
    SHOCK_Zeta_Foreign,

    v_Inflation_Foreign,
    v_Aggregated_Domestic_Good_Foreign,
    v_Return_Foreign,           /* Foreign interest rate */

    v_Tax_Labor,                /* Tax on Labor */
    v_Tax_Consumption,
        
    v_Gov_Good,   

    SHOCK_Inflation,

    OBS_Consumption,
    OBS_GDP,
    OBS_Exports,
    OBS_Imports,
    OBS_Invest,
    OBS_Inflation_Consumption,
    OBS_Inflation_Invest;     



varexo
    p_SHOCK_eta_eps_i,
    p_SHOCK_eta_eps_c,
    p_SHOCK_eta_eps_phi,
    p_SHOCK_eta_domestic_technology,
    p_SHOCK_eta_eps_l,
    
    p_SHOCK_eta_Inflation_domestic_good,
    p_SHOCK_eta_Inflation_import_good,
    p_SHOCK_eta_Inflation_Consumption,
    p_SHOCK_eta_Inflation_Investment,
    p_SHOCK_eta_Inflation_Government,
    p_SHOCK_eta_Inflation_Export,

    p_SHOCK_eta_Inflation,

    p_SHOCK_eta_Zeta,
    p_SHOCK_eta_Zeta_Foreign,
    
    p_eta_Inflation_Foreign,

    p_eta_Aggregated_Imported_Good_Foreign,
    p_eta_Return_Foreign,
    p_eta_Tax_Labor,
    p_eta_Tax_Consumption,
    p_eta_Gov_Good;

    

parameters
    p_Delta,                             /* Kapital depreciation rate*/
    p_Zeta_SS,
    p_Beta,                              /* Discount factor */
    p_Habit,                             /* Consumption habit */
    p_Inv_Elast_Work_Labor,              /* Inverse of the elasticity of work w.r.t. the marginal disutility of labor */
    p_Wage_Markup,                       /* Wage Markup. It is dependent on the elasticity of substitution between varieties of labor */
    p_bWage,
    p_ppStandByHouseholds,               /* Percent of Households which do not reoptimise wages*/
    p_Tax_Labor_SS,                      /* Tax on Labor */
    p_Degree_Wage_Indexation,            /* Degree of Wage Indexation*/
    p_Rho_Inflation_Bar,        
    p_Degree_Domestic_Price_Indexation,  /* Degree of Domestic price indexation */
    p_ppStandByDomesticFirms,            /* Percent of Domestic Firms which do not reoptimise prices */   
    p_K_Share,                           /* K share in the Cobb Douglas production function */
    p_Degree_Import_Price_Indexation,    /* Degree of import price indexation */
    p_ppStandByImportFirms,              /* Degree of Import Firms which do not reoptimise prices */
    p_Degree_Consumption_Indexation,
    p_Degree_Invest_Indexation,
    p_Degree_Government_Indexation,
    p_Degree_Export_Indexation,
    p_ppStandByConsumption,
    p_ppStandByInvest,
    p_ppStandByGovernment,
    p_ppStandByExport,
    p_Debt_SS,                           /* Government debt SS */
    p_GDP_SS,                            /* GDP SS */
    p_Debt_to_GDP_Target,                /* Deficit target */
    p_Primary_Deficit,
    p_Gov_Good_Price,
    p_Transfers_SS,
    p_Return_SS,
    p_Inflation_SS,
    p_Tax_Consumption_SS,
    p_Consumption_Good_Price,
    p_Wage_SS,
    p_Labor_SS,
    p_AggregatedPrice_SS,
    p_Share_Import_Goods,
    p_Price_Domestic_Good_SS,
    p_Elast_Subst_Dom_Imp,
    p_Price_Import_Good_SS,
    p_Elast_Subst_Dom_Imp_Foreign,
    p_Aggregated_Domestic_Good_SS,
    p_Consumption_SS,
    p_Investment_SS,
    p_Government_SS,
    p_Exports_SS,
    p_Price_Investment,
    p_Price_Export_Good,
    p_Imports_SS,

    /* Parameters for SHOCKS */
    p_SHOCK_rho_eps_i,
    p_SHOCK_rho_eps_c,
    p_SHOCK_rho_eps_phi,
    
    p_SHOCK_rho_eps_l,

   
    p_SHOCK_rho_domestic_technology,


    p_SHOCK_rho_Inflation_domestic_good,
    p_SHOCK_Inflation_Domestic_Good_SS, // don't we have another parameter for this defined?

    p_SHOCK_rho_Inflation_import_good,
    p_SHOCK_Inflation_Import_Good_SS,

    p_SHOCK_rho_Inflation_Consumption,
    p_SHOCK_Inflation_Consumption_SS,

    p_SHOCK_rho_Inflation_Investment,
    p_SHOCK_Inflation_Investment_SS,

    p_SHOCK_rho_Inflation_Government,
    p_SHOCK_Inflation_Government_SS,

    p_SHOCK_rho_Inflation_Export,
    p_SHOCK_Inflation_Export_SS,

    p_SHOCK_rho_Zeta,

    p_SHOCK_rho_Zeta_Foreign,

    p_rho_Inflation_Foreign,

    p_rho_Aggregated_Imported_Good_Foreign,

    p_rho_Return_Foreign,

    p_rho_Tax_Labor,

    p_rho_Tax_Consumption,

    p_rho_Gov_Good,

    p_S,                        /* transforms K into I */
    d_g,                        /* goes into the fiscal rule */
    r_k_SS,
    d1,
    d2,
    g_y,
    k_SS,
    k_l_SS;

/* Initialisation of parameters */    
    p_Delta = 0.33;//0.014;                             /* Kapital depreciation rate*/
    p_Habit = 0.65;                           /* Consumption habit */
    p_Beta = 0.999;                             /* Discount factor */
    p_Inv_Elast_Work_Labor=2;                /* Inverse of the elasticity of work w.r.t. the marginal disutility of labor */

    p_Wage_Markup=1.25;                         /* Wage Markup. It is dependent on the elasticity of substitution between varieties of labor */
    p_SHOCK_Inflation_Domestic_Good_SS = 1.15; // don't we have another parameter for this defined?
    p_SHOCK_Inflation_Import_Good_SS = 1.2;
    p_SHOCK_Inflation_Consumption_SS = 1.05;
    p_SHOCK_Inflation_Investment_SS = 1.05;
    p_SHOCK_Inflation_Government_SS = 1.05;
    p_SHOCK_Inflation_Export_SS = 1.05;
    p_Elast_Subst_Dom_Imp = 0.5; // vartheta
    p_K_Share=0.0123;//0.323;                          /* K share in the Cobb Douglas production function */
    p_Share_Import_Goods = 0.4;
    p_Inflation_SS = 1.005;

    g_y=0.13;//0.14;

    p_Tax_Consumption_SS = 0.19; //0.304;
    p_Tax_Labor_SS=0.16;//0.287;                      /* Tax on Labor */
    p_Zeta_SS= 1.005;                                  /* Growth rate of productivity of 2%/year. Is zt/zt(-1) */

    d_g = 0.9;
    
    p_Debt_to_GDP_Target=0.6;                /* Deficit target - according to the Maastricht criteria */
    p_Elast_Subst_Dom_Imp_Foreign = 0.5;    /* vartheta_for*/
    p_S = 13;//7.6;
    p_ppStandByHouseholds =0.84;              /* Percent of Households which do not reoptimise wages*/
    p_ppStandByDomesticFirms=0.79;            /* Percent of Domestic Firms which do not reoptimise prices */
    p_ppStandByImportFirms=0.5;              /* Degree of Import Firms which do not reoptimise prices */
    p_ppStandByConsumption=0.63;
    p_ppStandByInvest=0.63;
    p_ppStandByGovernment=0.63;
    p_ppStandByExport=0.44;                           
    p_bWage = (p_Wage_Markup*p_Inv_Elast_Work_Labor - (1-p_Wage_Markup))/((1-p_Beta*p_ppStandByHouseholds)*(1-p_ppStandByHouseholds));
    p_Degree_Wage_Indexation=0.5;             /* Degree of Wage Indexation*/

    p_Degree_Domestic_Price_Indexation=0.5;  /* Degree of Domestic price indexation */
    p_Degree_Import_Price_Indexation=0.5;    /* Degree of import price indexation */
    p_Degree_Consumption_Indexation=0.5;
    p_Degree_Invest_Indexation=0.5;
    p_Degree_Government_Indexation=0.5;
    p_Degree_Export_Indexation=0.5;

    /* Parameters for SHOCKS */
    p_SHOCK_rho_eps_i= 0.6;
    p_SHOCK_rho_eps_c = 0.6;
    p_SHOCK_rho_eps_phi = 0.6;
    p_SHOCK_rho_domestic_technology = 0.6;
    p_SHOCK_rho_eps_l = 0.6;

    p_SHOCK_rho_Inflation_domestic_good = 0.6;
    p_SHOCK_rho_Inflation_Consumption = 0.6;


    p_SHOCK_rho_Inflation_Investment = 0.6;  
    p_SHOCK_rho_Inflation_Government = 0.6;
    p_SHOCK_rho_Inflation_Export = 0.6;
    p_SHOCK_rho_Inflation_import_good = 0.6;
    

    p_SHOCK_rho_Zeta = 0.6;
    p_SHOCK_rho_Zeta_Foreign=0.6;


    p_rho_Tax_Labor = 0.6;
    p_rho_Tax_Consumption= 0.6;

    p_rho_Gov_Good = 0.6;

    p_rho_Inflation_Foreign = 0.6;//0.1;//0.6;

    p_rho_Aggregated_Imported_Good_Foreign = 0.6;//0.51;//0.6;

    p_rho_Return_Foreign = 0.6;//0.93;//0.6;
    p_Rho_Inflation_Bar=0.975;//0.6;        
   
    p_Return_SS = (p_Inflation_SS*p_Zeta_SS)/p_Beta;
    p_Consumption_Good_Price = 1/(1+p_Tax_Consumption_SS);
    p_Price_Import_Good_SS = p_SHOCK_Inflation_Import_Good_SS;
    p_AggregatedPrice_SS = p_Consumption_Good_Price / p_SHOCK_Inflation_Consumption_SS;
    p_Price_Investment = p_SHOCK_Inflation_Investment_SS * p_AggregatedPrice_SS;
    p_Gov_Good_Price = p_SHOCK_Inflation_Government_SS * p_AggregatedPrice_SS;
    p_Price_Export_Good = p_SHOCK_Inflation_Export_SS*p_AggregatedPrice_SS;

    p_Price_Domestic_Good_SS = ((p_AggregatedPrice_SS^(-p_Elast_Subst_Dom_Imp)-p_Share_Import_Goods*(p_Price_Import_Good_SS^(-p_Elast_Subst_Dom_Imp)))/(1-p_Share_Import_Goods))^(-1/p_Elast_Subst_Dom_Imp);
    
    r_k_SS = p_Price_Investment *(p_Zeta_SS/p_Beta-(1-p_Delta));
    p_Wage_SS = (p_Price_Domestic_Good_SS/(p_SHOCK_Inflation_Domestic_Good_SS*r_k_SS^p_K_Share)*p_K_Share^p_K_Share*(1-p_K_Share)^(1-p_K_Share))^(1/(1-p_K_Share));
    
    k_l_SS=p_K_Share/(1-p_K_Share)*(p_Zeta_SS*p_Wage_SS)/r_k_SS;

    d1 = (p_Wage_SS/p_Wage_Markup*(1-p_Tax_Labor_SS)*(p_Zeta_SS-p_Beta*p_Habit)/(p_Zeta_SS-p_Habit)*p_Zeta_SS)^(1/p_Inv_Elast_Work_Labor);    
    d2 = 1/(1-p_Share_Import_Goods)*(p_Price_Domestic_Good_SS/p_AggregatedPrice_SS)^(p_Elast_Subst_Dom_Imp+1)*(1-g_y-1/p_Price_Export_Good*p_Share_Import_Goods/
        (1-p_Share_Import_Goods)*(p_Price_Domestic_Good_SS/p_Price_Import_Good_SS)^(p_Elast_Subst_Dom_Imp+1))*
        1/p_SHOCK_Inflation_Domestic_Good_SS*(1/p_Zeta_SS*k_l_SS)^p_K_Share-(1-(1-p_Delta)/p_Zeta_SS)*k_l_SS;
    
    p_Labor_SS = (d1^p_Inv_Elast_Work_Labor/d2)^(1/(p_Inv_Elast_Work_Labor+1));
    p_Consumption_SS = d2 * p_Labor_SS;    
  
    p_Aggregated_Domestic_Good_SS = 1/p_SHOCK_Inflation_Domestic_Good_SS*(1/p_Zeta_SS)^p_K_Share*k_l_SS^p_K_Share*p_Labor_SS;

    p_Imports_SS = p_Share_Import_Goods/(1-p_Share_Import_Goods)*(p_Price_Domestic_Good_SS/p_Price_Import_Good_SS)^(p_Elast_Subst_Dom_Imp+1)*p_Aggregated_Domestic_Good_SS;

    k_SS = k_l_SS*p_Labor_SS;
    p_Investment_SS = (1-(1-p_Delta)/p_Zeta_SS)*k_SS;
    p_Exports_SS = p_Imports_SS/p_Price_Export_Good;

    p_Government_SS = g_y*p_Aggregated_Domestic_Good_SS;
    p_GDP_SS=p_Consumption_SS+ p_Price_Investment*p_Investment_SS +  p_Gov_Good_Price*p_Government_SS;     /* GDP SS */
    p_Debt_SS=d_g*p_Inflation_SS*p_Zeta_SS/(d_g*p_Inflation_SS*p_Zeta_SS + p_Inflation_SS*p_Zeta_SS - p_Return_SS)* p_Debt_to_GDP_Target*p_GDP_SS;  /* Government debt SS */   
    p_Transfers_SS = (1-p_Return_SS/(p_Inflation_SS*p_Zeta_SS))*p_Debt_SS-p_Gov_Good_Price*p_Government_SS + p_Tax_Consumption_SS*p_Consumption_Good_Price*p_Consumption_SS+p_Tax_Labor_SS*p_Wage_SS*p_Labor_SS;
    p_Primary_Deficit = p_Gov_Good_Price*p_Government_SS + p_Transfers_SS - p_Tax_Consumption_SS*p_Consumption_Good_Price*p_Consumption_SS - p_Tax_Labor_SS*p_Wage_SS*p_Labor_SS;
    

model(linear);
    
    v_C = 1/(p_Zeta_SS^2 + p_Beta*p_Habit^2)*( p_Zeta_SS*p_Habit*v_C(-1) - p_Zeta_SS*p_Habit*SHOCK_Zeta - p_Beta*p_Habit*(p_Zeta_SS-p_Habit)*SHOCK_eps_c(+1)
           + p_Beta*p_Habit*p_Zeta_SS*v_C(+1) + p_Beta*p_Habit*p_Zeta_SS*SHOCK_Zeta(+1) + p_Zeta_SS*(p_Zeta_SS-p_Habit)*SHOCK_eps_c - 
           (p_Zeta_SS - p_Beta*p_Habit)*(p_Zeta_SS - p_Habit) * v_Lambda_z  );

    v_Lambda_z = v_Lambda_z(+1) + v_Return_Domestic - v_Inflation(+1) - SHOCK_Zeta(+1);

    v_Return_Domestic = v_Return_Foreign - v_Bond_Foreign + SHOCK_eps_phi;

    v_K = (1-p_Delta)/p_Zeta_SS*(v_K(-1)- SHOCK_Zeta) + (1 - (1-p_Delta)/p_Zeta_SS)*(SHOCK_eps_i + v_I);

    v_I = 1/(1+p_Beta)*( (v_Q + SHOCK_eps_i - v_Price_Investment_Good)/(p_S*p_Zeta_SS^2) + v_I(-1) - SHOCK_Zeta +p_Beta*v_I(+1) + p_Beta*SHOCK_Zeta(+1) );

    v_Q = -(v_Return_Domestic - v_Inflation(+1)) + (p_Zeta_SS - (1-p_Delta))/p_Zeta_SS*v_Return_Kapital(+1) + (1-p_Delta)*p_Beta/p_Zeta_SS*v_Q(+1);
    
    v_Wage_Households = 1/(p_Inv_Elast_Work_Labor*p_Wage_Markup - p_bWage*(1+p_Beta*p_ppStandByHouseholds^2)) * 
            ( (1-p_Wage_Markup)*(-v_Lambda_z + p_Inv_Elast_Work_Labor*v_L + p_Tax_Labor_SS/(1-p_Tax_Labor_SS)*v_Tax_Labor + SHOCK_eps_l ) -
            p_bWage*p_ppStandByHouseholds*(p_Beta*v_Wage_Households(+1) + p_Beta*v_Inflation(+1) + v_Wage_Households(-1) - v_Inflation +
            p_Degree_Wage_Indexation*(v_Inflation(-1) - p_Beta*v_Inflation) +(1-p_Degree_Wage_Indexation)*(1-p_Beta*p_Rho_Inflation_Bar)*SHOCK_Inflation
            ));
/*======================================================================================================*/
    
    v_Return_Kapital = v_L - v_K(-1) + SHOCK_Zeta + v_Wage_Households;

    v_Inflation_Domestic_Good = 1/(1+p_Degree_Domestic_Price_Indexation*p_Beta)*
                    ((1-p_Degree_Domestic_Price_Indexation)*(1-p_Beta*p_Rho_Inflation_Bar)*SHOCK_Inflation +
                    p_Beta*v_Inflation_Domestic_Good(+1) + p_Degree_Domestic_Price_Indexation*v_Inflation_Domestic_Good(-1) +
                    (1-p_ppStandByDomesticFirms)*(1-p_Beta*p_ppStandByDomesticFirms)/p_ppStandByDomesticFirms *
                    (-SHOCK_domestic_technology + (1-p_K_Share)*v_Wage_Households + p_K_Share*v_Return_Kapital + SHOCK_Inflation_Domestic_Good)
                    );
    v_Inflation_Import_Good = 1/(1+p_Degree_Import_Price_Indexation*p_Beta)*
                    ((1-p_Degree_Import_Price_Indexation)*(1-p_Beta*p_Rho_Inflation_Bar)*SHOCK_Inflation + 
                    p_Beta*v_Inflation_Import_Good(+1) + p_Degree_Import_Price_Indexation*v_Inflation_Import_Good(-1) +
                    (1-p_ppStandByImportFirms)*(1-p_Beta*p_ppStandByImportFirms)/p_ppStandByImportFirms*(v_Price_Imported_Good_Foreign + SHOCK_Inflation_Import_Good)
                    );
    v_Inflation_Consumption = 1/(1+p_Degree_Consumption_Indexation*p_Beta)*
                    ((1-p_Degree_Consumption_Indexation)*(1-p_Rho_Inflation_Bar*p_Beta)*SHOCK_Inflation +
                    p_Beta*v_Inflation_Consumption(+1) + p_Degree_Consumption_Indexation*v_Inflation_Consumption(-1) +
                    (1-p_ppStandByConsumption)*(1-p_Beta*p_ppStandByConsumption)/p_ppStandByConsumption*(v_AggregatedPrice + SHOCK_Inflation_Consumption)
                    );
    v_Inflation_Invest = 1/(1+p_Degree_Invest_Indexation*p_Beta)*
                    ((1-p_Degree_Invest_Indexation)*(1-p_Rho_Inflation_Bar*p_Beta)*SHOCK_Inflation +
                    p_Beta*v_Inflation_Invest(+1) + p_Degree_Invest_Indexation*v_Inflation_Invest(-1) +
                    (1-p_ppStandByInvest)*(1-p_Beta*p_ppStandByInvest)/p_ppStandByInvest*(v_AggregatedPrice + SHOCK_Inflation_Investment)
                    );
    v_Inflation_Government = 1/(1+p_Degree_Government_Indexation*p_Beta)*
                    ((1-p_Degree_Government_Indexation)*(1-p_Rho_Inflation_Bar*p_Beta)*SHOCK_Inflation +
                    p_Beta*v_Inflation_Government(+1) + p_Degree_Government_Indexation*v_Inflation_Government(-1) +
                    (1-p_ppStandByGovernment)*(1-p_Beta*p_ppStandByGovernment)/p_ppStandByGovernment*(v_AggregatedPrice + SHOCK_Inflation_Government)
                    );
    v_Inflation_Export = 1/(1+p_Degree_Export_Indexation*p_Beta)*
                    ((1-p_Degree_Export_Indexation)*(1-p_Rho_Inflation_Bar*p_Beta)*SHOCK_Inflation +
                    p_Beta*v_Inflation_Export(+1) + p_Degree_Export_Indexation*v_Inflation_Export(-1) +
                    (1-p_ppStandByExport)*(1-p_Beta*p_ppStandByExport)/p_ppStandByExport*(v_AggregatedPrice + SHOCK_Inflation_Export)
                    );
/*======================================================================================================*/

    v_L = 1/(1-p_K_Share)*(v_Aggregated_Domestic_Good/p_SHOCK_Inflation_Domestic_Good_SS - SHOCK_domestic_technology - p_K_Share*(v_K(-1)-SHOCK_Zeta));

    v_Exports = (p_Elast_Subst_Dom_Imp_Foreign+1)*v_Price_Imported_Good_Foreign + SHOCK_Zeta_Foreign + v_Aggregated_Domestic_Good_Foreign;    
    v_Imports = (p_Elast_Subst_Dom_Imp + 1)*(v_Price_Domestic_Good - v_Price_Import_Good) + v_Aggregated_Domestic_Good;

    v_Aggregated_Domestic_Good = (p_Elast_Subst_Dom_Imp + 1)*(v_AggregatedPrice - v_Price_Domestic_Good) +
                                1/p_Aggregated_Domestic_Good_SS*(p_Consumption_SS*v_C + p_Investment_SS*v_I + p_Government_SS*v_Gov_Good + p_Exports_SS*v_Exports );
    
    v_Debt = (p_Debt_SS/p_GDP_SS - p_Debt_to_GDP_Target)*p_GDP_SS/p_Debt_SS*
             ( 1/p_Primary_Deficit*(p_Gov_Good_Price*p_Government_SS*(v_Gov_Good + v_Gov_Good_Price) +
                p_Transfers_SS*
                (1/p_Transfers_SS*( p_Debt_SS *(v_Debt - p_Return_SS/(p_Zeta_SS*p_Inflation_SS)*( v_Debt(-1) - SHOCK_Zeta - v_Inflation + v_Return_Domestic(-1)))
                - p_Gov_Good_Price*p_Government_SS*(v_Gov_Good + v_Gov_Good_Price) + p_Tax_Consumption_SS*p_Consumption_Good_Price*p_Consumption_SS*(v_C + v_Tax_Consumption + v_Consumption_Price) +
                p_Tax_Labor_SS*p_Wage_SS*p_Labor_SS*(v_L + v_Wage_Households + v_Tax_Labor)
                 )) /* end Transfers */
                - p_Tax_Consumption_SS*p_Consumption_Good_Price*p_Consumption_SS*(v_C + v_Tax_Consumption + v_Consumption_Price)
                - p_Tax_Labor_SS*p_Wage_SS*p_Labor_SS*(v_L + v_Wage_Households + v_Tax_Labor)) /* end Primary Deficit */
              );

    /* Foreign bond market clearing condition */
    v_Bond_Foreign = p_Imports_SS*(v_Exports + v_Price_Export_Good - v_Imports - v_Price_Imported_Good_Foreign)+ p_Return_SS/(p_Inflation_SS*p_Zeta_SS)*v_Bond_Foreign(-1);
    
   v_GDP = 1/p_GDP_SS*(p_Consumption_SS*v_C + p_Gov_Good_Price*p_Government_SS*(v_Gov_Good + v_Gov_Good_Price)
            + p_Price_Investment*p_Investment_SS*(v_I + v_Price_Investment_Good) + p_Price_Export_Good*p_Exports_SS*(v_Exports+v_Price_Export_Good)
            - p_Imports_SS*(v_Imports + v_Price_Imported_Good_Foreign)
              );

    /* Numeraire inflation */
    v_Consumption_Price = - p_Tax_Consumption_SS*v_Tax_Consumption/(1+p_Tax_Consumption_SS);

    /* Inflation identity */
    v_Inflation = v_Consumption_Price(-1) + v_Inflation_Consumption - v_Consumption_Price;

    v_AggregatedPrice = 1/p_AggregatedPrice_SS*((1-p_Share_Import_Goods)*p_Price_Domestic_Good_SS^(-p_Elast_Subst_Dom_Imp)*v_Price_Domestic_Good
                        + p_Share_Import_Goods*p_Price_Import_Good_SS^(-p_Elast_Subst_Dom_Imp)*v_Price_Import_Good);


    v_Price_Domestic_Good = v_Price_Domestic_Good(-1) + v_Inflation_Domestic_Good - v_Inflation;

    v_Price_Import_Good = v_Price_Import_Good(-1) + v_Inflation_Import_Good - v_Inflation;

    v_Price_Investment_Good = v_Price_Investment_Good(-1) + v_Inflation_Invest - v_Inflation;

    v_Gov_Good_Price = v_Gov_Good_Price(-1) + v_Inflation_Government - v_Inflation;

    v_Price_Export_Good = v_Price_Export_Good(-1) + v_Inflation_Export - v_Inflation;

    v_Price_Imported_Good_Foreign = v_Price_Imported_Good_Foreign(-1) + v_Inflation_Foreign - v_Inflation;

    /* SHOCKS */
    SHOCK_eps_i                     = p_SHOCK_rho_eps_i*SHOCK_eps_i(-1) + p_SHOCK_eta_eps_i;
    SHOCK_eps_c                     = p_SHOCK_rho_eps_c*SHOCK_eps_c(-1) + p_SHOCK_eta_eps_c;
    SHOCK_eps_phi                   = p_SHOCK_rho_eps_phi*SHOCK_eps_phi(-1) + p_SHOCK_eta_eps_phi;
    SHOCK_eps_l                     = p_SHOCK_rho_eps_l*SHOCK_eps_l(-1) + p_SHOCK_eta_eps_l;
    SHOCK_domestic_technology       = p_SHOCK_rho_domestic_technology*SHOCK_domestic_technology(-1) + p_SHOCK_eta_domestic_technology;
    

    SHOCK_Inflation_Domestic_Good   = p_SHOCK_rho_Inflation_domestic_good*SHOCK_Inflation_Domestic_Good(-1) + p_SHOCK_eta_Inflation_domestic_good/p_SHOCK_Inflation_Domestic_Good_SS;
    SHOCK_Inflation_Import_Good     = p_SHOCK_rho_Inflation_import_good*SHOCK_Inflation_Import_Good(-1) + p_SHOCK_eta_Inflation_import_good/p_SHOCK_Inflation_Import_Good_SS;
    SHOCK_Inflation_Consumption     = p_SHOCK_rho_Inflation_Consumption*SHOCK_Inflation_Consumption(-1) + p_SHOCK_eta_Inflation_Consumption/p_SHOCK_Inflation_Consumption_SS;
    SHOCK_Inflation_Investment      = p_SHOCK_rho_Inflation_Investment*SHOCK_Inflation_Investment(-1) + p_SHOCK_eta_Inflation_Investment/p_SHOCK_Inflation_Investment_SS;
    SHOCK_Inflation_Government      = p_SHOCK_rho_Inflation_Government*SHOCK_Inflation_Government(-1) + p_SHOCK_eta_Inflation_Government/p_SHOCK_Inflation_Government_SS;
    SHOCK_Inflation_Export          = p_SHOCK_rho_Inflation_Export*SHOCK_Inflation_Export(-1) + p_SHOCK_eta_Inflation_Export/p_SHOCK_Inflation_Export_SS;

    SHOCK_Zeta                      = p_SHOCK_rho_Zeta*SHOCK_Zeta(-1) + p_SHOCK_eta_Zeta/p_Zeta_SS;
    SHOCK_Zeta_Foreign              = p_SHOCK_rho_Zeta_Foreign*SHOCK_Zeta_Foreign(-1) + p_SHOCK_eta_Zeta_Foreign;

    SHOCK_Inflation                 = p_Rho_Inflation_Bar*SHOCK_Inflation(-1) + p_SHOCK_eta_Inflation/p_Inflation_SS;
    

    v_Inflation_Foreign            = p_rho_Inflation_Foreign*v_Inflation_Foreign(-1) + p_eta_Inflation_Foreign/p_Inflation_SS;
    v_Aggregated_Domestic_Good_Foreign  = p_rho_Aggregated_Imported_Good_Foreign*v_Aggregated_Domestic_Good_Foreign(-1) + p_eta_Aggregated_Imported_Good_Foreign;
    v_Return_Foreign                = p_rho_Return_Foreign*v_Return_Foreign(-1) + p_eta_Return_Foreign/p_Return_SS;

    v_Tax_Labor                     = p_rho_Tax_Labor*v_Tax_Labor(-1) + p_eta_Tax_Labor/p_Tax_Labor_SS;
    v_Tax_Consumption               = p_rho_Tax_Consumption*v_Tax_Consumption(-1) + p_eta_Tax_Consumption/p_Tax_Consumption_SS;

    v_Gov_Good                      = p_rho_Gov_Good*v_Gov_Good(-1) + p_eta_Gov_Good/p_Government_SS;

    /* *** MEASUREMENT EQUATIONS *** */
    OBS_Consumption = v_C - v_C(-1);
    OBS_GDP = v_GDP - v_GDP(-1);
    OBS_Exports = v_Exports - v_Exports(-1);
    OBS_Imports = v_Imports - v_Imports(-1);
    OBS_Invest = v_I - v_I(-1);
    //OBS_Inflation_Consumption = v_Inflation_Consumption - v_Inflation_Consumption(-1);
    //OBS_Inflation_Invest = v_Inflation_Invest - v_Inflation_Invest(-1);
end; //model

initval;
    v_K=0;                        /* Kapital */
    v_I=0;                        /* Investment */
    v_C=0;                        /* Consumption */
    v_Lambda_z=0;                 /* Utility */
    v_Return_Domestic =0;         /* Domestic interest rate */
    v_Inflation=0;                /* Inflation rate */
    v_Return_Foreign=0;           /* Foreign interest rate */
    v_Bond_Foreign=0;             /* Foreign Bond */
    v_Q=0;                        /* Marginal utility of capital */
    v_Return_Kapital=0;           /* Return on Kapital */
    v_Wage_Households=0;          /* Wage households */
    v_L=0;                        /* Labor */
    v_Tax_Labor=0;                /* Tax on Labor */
    v_Inflation_Domestic_Good=0;  /* Inflation for domestic goods */    
    v_Inflation_Import_Good=0;    /* Inflation for import goods */   
    v_Inflation_Consumption=0;     /* Inflation for consumption */
    v_Inflation_Invest=0;
    v_Inflation_Government=0;
    v_Inflation_Export=0;
    v_AggregatedPrice=0;
    v_Debt=0;                     /* Debt of the government */
    v_Gov_Good=0;
    v_Gov_Good_Price=0;
    v_Tax_Consumption=0;
    v_Consumption_Price=0;
    v_Aggregated_Domestic_Good=0;
    v_Price_Domestic_Good=0;
    v_Price_Import_Good=0;
    v_Imports=0;
    v_Exports=0;
    v_Price_Imported_Good_Foreign=0;
    v_Aggregated_Domestic_Good_Foreign=0;
    v_GDP=0;
    v_Price_Investment_Good=0;
    v_Price_Export_Good=0;
    v_Inflation_Foreign=0;

    /* SHOCKS */
    SHOCK_eps_i=0;                 /* Investment shock */
    SHOCK_eps_c=0;                 /* Consumption shock*/
    SHOCK_eps_phi=0;               /* UIP shock*/
    SHOCK_eps_l=0;                 /* Labor shock */

    SHOCK_domestic_technology=0;   /* Domestic stationary technology shock*/
    SHOCK_Inflation_Domestic_Good=0;
    SHOCK_Inflation_Import_Good=0;
    SHOCK_Inflation_Consumption=0; /* Shock to inflation consumption */
    SHOCK_Inflation_Investment=0;
    SHOCK_Inflation_Government=0;
    SHOCK_Inflation_Export=0;

    SHOCK_Zeta=0;
    SHOCK_Zeta_Foreign=0;

    SHOCK_Inflation =0;    

/* SHOCKS */
    p_SHOCK_eta_eps_i=0;
    p_SHOCK_eta_eps_c=0;
    p_SHOCK_eta_eps_phi=0;
    p_SHOCK_eta_eps_l=0;
    p_SHOCK_eta_domestic_technology=0;
    p_SHOCK_eta_Inflation_domestic_good=0;
    p_SHOCK_eta_Inflation_import_good=0;
    p_SHOCK_eta_Inflation_Consumption=0;
    p_SHOCK_eta_Inflation_Investment=0;
    p_SHOCK_eta_Inflation_Government=0;
    p_SHOCK_eta_Inflation_Export=0;
    p_SHOCK_eta_Zeta=0;
    p_SHOCK_eta_Zeta_Foreign=0;
    p_SHOCK_eta_Inflation=0;
    p_eta_Inflation_Foreign=0;
    p_eta_Aggregated_Imported_Good_Foreign=0;
    p_eta_Return_Foreign=0;
    p_eta_Tax_Labor=0;
    p_eta_Tax_Consumption=0;
    p_eta_Gov_Good=0;
end; //initval

/*
shocks;
var    p_SHOCK_eta_eps_i;                     stderr 0.15;
var    p_SHOCK_eta_eps_c;                     stderr 0.15;
var    p_SHOCK_eta_eps_phi;                   stderr 0.02;
var    p_SHOCK_eta_eps_l;                     stderr 0.15;
var    p_SHOCK_eta_domestic_technology;       stderr 0.02;
var    p_SHOCK_eta_Inflation_domestic_good;   stderr 0.15;
var    p_SHOCK_eta_Inflation_import_good;     stderr 0.15;
var    p_SHOCK_eta_Inflation_Consumption;     stderr 0.15;
var    p_SHOCK_eta_Inflation_Investment;      stderr 0.15;
var    p_SHOCK_eta_Inflation_Government;      stderr 0.15;
var    p_SHOCK_eta_Inflation_Export;          stderr 0.15;
var    p_SHOCK_eta_Zeta;                      stderr 0.15;
var    p_SHOCK_eta_Zeta_Foreign;              stderr 0.15;
var    p_SHOCK_eta_Inflation;                 stderr 0.02;
var    p_eta_Inflation_Foreign;               stderr 0.02;
var    p_eta_Aggregated_Imported_Good_Foreign;stderr 0.02;
var    p_eta_Return_Foreign;                  stderr 0.02;
var    p_eta_Tax_Labor;                       stderr 0.15;
var    p_eta_Tax_Consumption;                 stderr 0.02;
var    p_eta_Gov_Good;                        stderr 0.02;
end;*/ // end shocks

steady;
check;

estimated_params;
    p_Wage_Markup,inv_gamma_pdf,                                1.25,   0.2;
    p_SHOCK_Inflation_Domestic_Good_SS,inv_gamma_pdf,           1.15,   0.2;
    p_SHOCK_Inflation_Import_Good_SS,inv_gamma_pdf,             1.2,    0.2;
    p_SHOCK_Inflation_Consumption_SS,inv_gamma_pdf,             1.05,   0.2;
    p_SHOCK_Inflation_Investment_SS,inv_gamma_pdf,              1.05,   0.2;
    p_SHOCK_Inflation_Government_SS,inv_gamma_pdf,              1.05,   0.2;
    p_SHOCK_Inflation_Export_SS,inv_gamma_pdf,                  1.05,   0.2;
    p_Elast_Subst_Dom_Imp,inv_gamma_pdf,                        0.5,    0.1;
    p_Share_Import_Goods,beta_pdf,                              0.4,    0.1;
    p_Elast_Subst_Dom_Imp_Foreign,inv_gamma_pdf,                0.5,    0.1;
    p_S,normal_pdf,                                             7.6,    1.5;
    p_ppStandByHouseholds,beta_pdf,                             0.84,   0.1;
    p_ppStandByDomesticFirms,beta_pdf,                          0.79,   0.1;
    p_ppStandByInvest,beta_pdf,                                 0.63,   0.1;
    p_ppStandByGovernment,beta_pdf,                             0.63,   0.1;
    p_ppStandByExport,beta_pdf,                                 0.44,   0.1;
    p_Degree_Wage_Indexation,beta_pdf,                          0.5,    0.1;
    p_Degree_Domestic_Price_Indexation,beta_pdf,                0.5,    0.1;
    p_Degree_Import_Price_Indexation,beta_pdf,                  0.5,    0.1;
    p_Degree_Consumption_Indexation,beta_pdf,                   0.5,    0.1;
    p_Degree_Invest_Indexation,beta_pdf,                        0.5,    0.1;
    p_Degree_Government_Indexation,beta_pdf,                    0.5,    0.1;
    p_Degree_Export_Indexation,beta_pdf,                        0.5,    0.1;
    p_SHOCK_rho_eps_i,beta_pdf,                                 0.6,    0.1;
    p_SHOCK_rho_eps_c,beta_pdf,                                 0.6,    0.1;
    p_SHOCK_rho_eps_phi,beta_pdf,                               0.6,    0.1;
    p_SHOCK_rho_domestic_technology,beta_pdf,                   0.6,    0.1;
    p_SHOCK_rho_eps_l,beta_pdf,                                 0.6,    0.1;
    p_SHOCK_rho_Inflation_domestic_good,beta_pdf,               0.6,    0.1;
    p_SHOCK_rho_Inflation_Consumption,beta_pdf,                 0.6,    0.1;
    p_SHOCK_rho_Inflation_Investment,beta_pdf,                  0.6,    0.1;
    p_SHOCK_rho_Inflation_Government,beta_pdf,                  0.6,    0.1;
    p_SHOCK_rho_Inflation_Export,beta_pdf,                      0.6,    0.1;
    p_SHOCK_rho_Inflation_import_good,beta_pdf,                 0.6,    0.1;
    p_SHOCK_rho_Zeta,beta_pdf,                                  0.6,    0.1;
    p_SHOCK_rho_Zeta_Foreign,beta_pdf,                          0.6,    0.1;
    p_rho_Tax_Labor,beta_pdf,                                   0.6,    0.1;
    p_rho_Tax_Consumption,beta_pdf,                             0.6,    0.1;
    p_rho_Gov_Good,beta_pdf,                                    0.6,    0.1;
    p_rho_Inflation_Foreign,beta_pdf,                           0.6,    0.1;
    p_rho_Aggregated_Imported_Good_Foreign,beta_pdf,            0.6,    0.1;
    p_rho_Return_Foreign,beta_pdf,                              0.6,    0.1;
    p_Rho_Inflation_Bar,beta_pdf,                               0.6,   0.1;

    stderr p_SHOCK_eta_eps_i,inv_gamma_pdf,                     0.15,   0.15;
    stderr p_SHOCK_eta_eps_c,inv_gamma_pdf,                     0.15,   0.15;
    stderr p_SHOCK_eta_eps_phi,inv_gamma_pdf,                   0.02,   0.02;
    stderr p_SHOCK_eta_domestic_technology,inv_gamma_pdf,       0.02,   0.02;
    stderr p_SHOCK_eta_eps_l,inv_gamma_pdf,                     0.15,   0.15;
    stderr p_SHOCK_eta_Inflation_domestic_good,inv_gamma_pdf,   0.15,   0.15;
    stderr p_SHOCK_eta_Inflation_Consumption,inv_gamma_pdf,     0.15,   0.15;
    stderr p_SHOCK_eta_Inflation_Investment,inv_gamma_pdf,      0.15,   0.15;
    stderr p_SHOCK_eta_Inflation_Government,inv_gamma_pdf,      0.15,   0.15;
    stderr p_SHOCK_eta_Inflation_Export,inv_gamma_pdf,          0.15,   0.15;
    stderr p_SHOCK_eta_Inflation_import_good,inv_gamma_pdf,     0.15,   0.15;
    stderr p_SHOCK_eta_Zeta,inv_gamma_pdf,                      0.15,   0.15;
    stderr p_SHOCK_eta_Zeta_Foreign,inv_gamma_pdf,              0.15,   0.15;
    stderr p_eta_Tax_Labor,inv_gamma_pdf,                       0.15,   0.15;
    stderr p_eta_Tax_Consumption,inv_gamma_pdf,                 0.02,   0.02;
    stderr p_eta_Gov_Good,inv_gamma_pdf,                        0.02,   0.02;
    stderr p_eta_Inflation_Foreign,inv_gamma_pdf,               0.02,   0.02;
    stderr p_eta_Aggregated_Imported_Good_Foreign,inv_gamma_pdf,0.02,   0.02;
    stderr p_eta_Return_Foreign,inv_gamma_pdf,                  0.02,   0.02;
    stderr p_SHOCK_eta_Inflation,inv_gamma_pdf,                 0.02,   0.02;
end;

varobs OBS_GDP, OBS_Consumption, OBS_Invest, OBS_Exports, OBS_Imports;

estimation(datafile=FinalDataSet_HP,xls_sheet=Final_data, conf_sig = 0.95, plot_priors = 0, mode_check,mh_nblocks=2,mh_jscale=0.3,mh_replic=10000, mode_compute=4, lik_init=2) OBS_Consumption, OBS_GDP, OBS_Exports, OBS_Imports, OBS_Invest;
