// stephane [DOT] adjemian [AT] ens [DOT] fr

/*
** MACROs
*/


// Add an efficient block (without nominal rigidities), used to define the output gap.
@#define efficient_block = 1


@#define NumberOfShocks  = 0
@#define ar_variance_decrease  = "1.0"

@#define ExogenousVariables_vnames = ["ProductionEfficiencyGrowth"]
@#define ExogenousVariables_inames = ["EfficiencyGrowthInnovation"]
@#define ExogenousVariables_pnames = ["production_efficiency_growth"]
@#define ExogenousVariables_nblags = [1]
@#define ExogenousVariables_acorr1_mode = [".3919"]
@#define ExogenousVariables_acorr1_std = [".02"]
@#define ExogenousVariables_vtexnames = ["A_T"]
@#define ExogenousVariables_sstexnames = ["\overline A_T"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["ProductionEfficiencyCycle"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["EfficiencyCycleInnovation"] 
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["production_efficiency"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".6001"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".10"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["A_C"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\overline A_C"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["ConsumptionTax"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["ConsumptionTaxInnovation"] 
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["consumption_tax"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".0000"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".10"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\tau_C"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar \tau_C"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["LabourIncomeTax"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["LabourIncomeTaxInnovation"] 
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["labour_income_tax"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".0000"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".02"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\tau_W"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar \tau_W"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["IncomeTax"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["IncomeTaxInnovation"] 
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["income_tax"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".0000"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".02"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\tau_R"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar \tau_R"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["RiskPremium"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["RiskPremiumInnovation"]
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["risk_premium"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".9090"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".10"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\varepsilon_B"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar\varepsilon_B"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["LabourSupplyShock"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["LabourSupplyInnovation"]
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["labour_supply"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".7035"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".10"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\varepsilon_L"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\widetilde L"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["InvestmentRelativePrice"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["InvestmentRelativePriceInnovation"] 
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["investment_relative_price"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".6223"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".02"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["p_I"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar p_I"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["InvestmentEfficiencyShock"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["InvestmentEfficiencyInnovation"] 
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["investment_efficiency"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".6289"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".10"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\varepsilon_I"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar\varepsilon_I"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["LabourTax"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["LabourTaxInnovation"] 
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["labour_tax"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".0000"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".02"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\tau_L"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar\tau_L"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["PriceMarkUpShock"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["PriceMarkUpInnovation"]
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["price_mark_up"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".8050"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".10"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\varepsilon_y"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar\varepsilon_y"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["WageMarkUpShock"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["WageMarkUpInnovation"] 
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["wage_mark_up"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".7400"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".05"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\varepsilon_l"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar\varepsilon_l"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["InflationTarget"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["InflationTargetInnovation"]
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["inflation_target"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".0000"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".10"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\bar\pi"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar\pi"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["TaylorShock"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["TaylorInnovation"] 
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["taylor"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".6388"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".10"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\varepsilon_R"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar\varepsilon_R"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["PublicSpendingShare"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["PublicSpendingShareInnovation"] 
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["public_spending"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".7135"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".02"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\varepsilon_g"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar\varepsilon_g"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["HabitShock"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["HabitInnovation"] 
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["habit"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".98"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".02"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\eta^s"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar\eta^s"]
@#define NumberOfShocks  = NumberOfShocks + 1

@#define ExogenousVariables_vnames = ExogenousVariables_vnames + ["PreferenceShock"]
@#define ExogenousVariables_inames = ExogenousVariables_inames + ["PreferenceInnovation"] 
@#define ExogenousVariables_pnames = ExogenousVariables_pnames + ["preference"]
@#define ExogenousVariables_nblags = ExogenousVariables_nblags + [1]
@#define ExogenousVariables_acorr1_mode = ExogenousVariables_acorr1_mode + [".9000"]
@#define ExogenousVariables_acorr1_std = ExogenousVariables_acorr1_std + [".02"]
@#define ExogenousVariables_vtexnames = ExogenousVariables_vtexnames + ["\varsigma"]
@#define ExogenousVariables_sstexnames = ExogenousVariables_sstexnames + ["\bar\varsigma"]
@#define NumberOfShocks  = NumberOfShocks + 1

// AutoregressiveProcesses(i,1)  [string]  Name of the variable.
// AutoregressiveProcesses(i,2)  [string]  Generic name of the autoregressive parameters
// AutoregressiveProcesses(i,3)  [integer] Number of lags.

global AutoregressiveProcesses; % Needed in the steady state file, where we have to update parameters related to the exogenous variables.
AutoregressiveProcesses = cell(@{NumberOfShocks},3);
@#for shock in 1:NumberOfShocks
  AutoregressiveProcesses(@{shock},1) = {'@{ExogenousVariables_vnames[shock]}'} ;
  AutoregressiveProcesses(@{shock},2) = {'@{ExogenousVariables_pnames[shock]}'} ;
  AutoregressiveProcesses(@{shock},3) = { @{ExogenousVariables_nblags[shock]} } ;
@#endfor


/*
** MOD FILE CORE
*/

/* 84 Endogenous variables (if efficient_block is equal to 1) */ 
var
    /* Households */
    Consumption
    HouseholdLabourSupply
    HouseholdLagrangeMultiplier
    Investment
    CapitalStock
    DepreciationRate
    dDepreciationRate
    InvestmentCost
    dInvestmentCost
    CapacityUtilizationFactor
    CapitalReturnRate
    HouseholdRealWage
    TobinQ
    /* Prices */
    RealGrossWage
    LabourDemand
    CapitalDemand
    RealMarginalCost
    OptimalRelativePrice
    Z1
    Z2
    Z3
    GDP
    FinalGoodLagrangeMultiplier
    NonOptimizingFirmsPriceGrowth
    AveragedRelativePrices
    PriceDistorsion
    NablaPrice
    InflationFactor
    /* Wages */
    RealWageGrowthFactor
    AveragedRelativeWages
    OptimalRelativeRealWage
    H1
    H2
    H3
    EmploymentAgencyLagrangeMultiplier
    EmploymentAgencyLabourSupply
    NonOptimizingUnionsWageGrowth
    WageDistorsion
    NablaWage	    
    /* Monetary authority and Government */
    NominalInterestFactor
    OutputGap
    PublicSpending
    /* Efficient variables (model without nominal rigidities) */    
    @#if (efficient_block==1)
      EfficientConsumption
      EfficientHouseholdLabourSupply
      EfficientHouseholdLagrangeMultiplier
      EfficientInvestment
      EfficientCapitalStock
      EfficientDepreciationRate
      dEfficientDepreciationRate
      EfficientInvestmentCost
      dEfficientInvestmentCost
      EfficientCapacityUtilizationFactor
      EfficientCapitalReturnRate
      EfficientHouseholdRealWage
      EfficientTobinQ
      EfficientRealInterestFactor
      EfficientLabourDemand
      EfficientRealMarginalCost
      EfficientGDP
      EfficientCapitalDemand
      EfficientRealGrossWage
    @#endif
    /* Shocks */
    @#for shock in 1:NumberOfShocks
      @{ExogenousVariables_vnames[shock]}
    @#endfor
    ;




/* 15 Exogenous variables */
varexo
    @#for shock in 1:NumberOfShocks
      @{ExogenousVariables_inames[shock]}
    @#endfor
    ;

parameters
       /*
       ** Household
       */
       sigmac $\sigma_c$
       sigmal $\sigma_l$
       eta $\eta$
       beta $\beta$
       investment_cost_size $\psi$
       capacity_utilization_factor_ss $\bar z$
       depreciation_rate_ss $\bar \delta$
       first_derivate_depreciation_rate_ss $\bar \delta''$	
       household_labour_supply_ss $\overline L$
       steady_state_investment_ratio $\frac{I}{Y}$
       /* 
       ** Prices
       */
       alpha $\alpha$
       thetaf $\theta_f$
       psif $\psi_f$
       xip $\xi_p$
       price_contract_length $\frac{1}{1-\xi_p}$
       gammap $\gamma_p$
       steady_state_mark_up_f $\mu_f$
       steady_state_labour_share $\frac{wL}{Y}$
       kimball_curvature_f $\epsilon_f$        
       /* 
       ** Wages 
       */
       psis $\psi_s$
       thetas $\theta_s$
       xiw $\xi_w$
       wage_contract_length $\frac{1}{1-\xi_w}$
       gammaw $\gamma_w$
       steady_state_mark_up_s $\mu_s$
       kimball_curvature_s $\epsilon_f$
       /* 
       ** Monetary authority 
       */
       @#if (efficient_block==0)
         ssGDP $\bar Y$
       @#endif
       steady_state_nominal_interest_factor $\bar R$
       steady_state_real_interest_factor $\bar r$
       nominal_interest_rate_smoothing $\rho_R$
       elasticity_of_nominal_interest_rate_to_inflation $r_{\pi}$
       elasticity_of_nominal_interest_rate_to_output_gap $r_y$
       elasticity_of_nominal_interest_rate_to_inflation_growth $r_{\Delta \pi}$
       elasticity_of_nominal_interest_rate_to_output_gap_growth $r_{\Delta y}$
       /* 
       ** Parameters related to exogenous processes 
       */
       @#for shock in 1:NumberOfShocks
         @#if (ExogenousVariables_nblags[shock]>0)
           @#for lag in 1:ExogenousVariables_nblags[shock]
             @{ExogenousVariables_pnames[shock]}_ar@{lag} $\rho_{@{ExogenousVariables_vtexnames[shock]},@{lag}}$
             @{ExogenousVariables_pnames[shock]}_rho@{lag} $\rho_{@{ExogenousVariables_vtexnames[shock]}}(@{lag})$
           @#endfor
         @#endif
         @{ExogenousVariables_pnames[shock]}_i_std
         @{ExogenousVariables_pnames[shock]}_std $\sqrt{\mathbb V[@{ExogenousVariables_vtexnames[shock]}]}$
         @{ExogenousVariables_pnames[shock]}_ss $ @{ExogenousVariables_sstexnames[shock]} $
       @#endfor
       Epsilon // This is not a parameter of the model.
;      



/*
** ??talonnage des param??tres
*/

beta   = 0.9975 ;
sigmac = 0.8514 ;
sigmal = 1.7180 ;
eta    = 0.1836 ;
price_contract_length = 1.6824; // quarters
wage_contract_length  = 4.6296;  // quarters
gammap = 0.2079 ;
gammaw = 0.2757 ;
// Is this parameter needed? --> steady_state_investment_ratio = 0.2094; 
steady_state_mark_up_f = 1.1931 ;
steady_state_mark_up_s = 1.2027 ;

production_efficiency_growth_ss      = 0.0031 ;
production_efficiency_ss             = 1.0000 ;
inflation_target_ss                  = 1.0050 ;
steady_state_nominal_interest_factor = 1.0100 ;
steady_state_real_interest_factor    = steady_state_nominal_interest_factor / inflation_target_ss ;
consumption_tax_ss                   = 1.0000 ;//1.1106 ;
income_tax_ss                        = 1.0000 ;//0.8814 ;
labour_income_tax_ss                 = 1.0000 ;//0.8730 ;
labour_tax_ss                        = 1.0000 ;
preference_ss                        = 1.0000 ;
investment_relative_price_ss         = 1.0000 ;
investment_efficiency_ss             = 1.0000 ;
risk_premium_ss                      = 1.0000 ;
labour_supply_ss                     = 1.0000 ;//0.1800 ;
taylor_ss                            = 1.0000 ;
public_spending_ss                   = 0.2500 ;//0.2181 ;
wage_mark_up_ss                      = 1.0000 ;
price_mark_up_ss                     = 1.0000 ;
investment_cost_size                 = 0.2361 ;
habit_ss                             = 1.0000 ;
capacity_utilization_factor_ss       = 0.8012 ;
depreciation_rate_ss                 = 0.0250 ;//0.0200 ;

steady_state_labour_share = (1-0.3030)/(labour_tax_ss*steady_state_mark_up_f);//0.3914 ;

kimball_curvature_f = -(-4.8380)*steady_state_mark_up_f/(steady_state_mark_up_f-1);//10.3333;
kimball_curvature_s = -(-5.5056)*steady_state_mark_up_s/(steady_state_mark_up_s-1);//*10.3333;
 
household_labour_supply_ss = 0.2712;

nominal_interest_rate_smoothing                          = 0.5807 ;//0.8400 ;
elasticity_of_nominal_interest_rate_to_inflation         = 1.4290 ;//1.5000 ;
elasticity_of_nominal_interest_rate_to_output_gap        = 1.7418 ;//0.1400 ;
elasticity_of_nominal_interest_rate_to_inflation_growth  = 0.0000 ;
elasticity_of_nominal_interest_rate_to_output_gap_growth = 0.0000 ;               


production_efficiency_growth_rho1 = .3919 ;
production_efficiency_rho1 = .6001 ;
consumption_tax_rho1 = .0000 ;
labour_income_tax_rho1 = .0000 ;
income_tax_rho1 = .0000 ;
risk_premium_rho1 = .9090 ;
labour_supply_rho1 = .7035 ;
investment_relative_price_rho1 = .6223 ;
investment_efficiency_rho1 = .6289 ;
labour_tax_rho1 = .0000 ;
price_mark_up_rho1 = .8050 ;
wage_mark_up_rho1 = .7400 ;
inflation_target_rho1 = .0000 ;
taylor_rho1 = .6388 ;
public_spending_rho1 = .7135 ;
habit_rho1 = .9800;
preference_rho1 = .9000;

production_efficiency_growth_std   = sqrt(0.0058^2/(1-production_efficiency_growth_rho1^2));
production_efficiency_std          = sqrt(0.0209^2/(1-production_efficiency_rho1^2));
risk_premium_std                   = sqrt(0.0048^2/(1-risk_premium_rho1^2));
consumption_tax_std                = 0.0000;
labour_income_tax_std              = 0.0000;
income_tax_std                     = 0.0000;
labour_supply_std                  = sqrt(0.0077^2/(1-labour_supply_rho1^2));
investment_relative_price_std      = sqrt(0.0055^2/(1-investment_relative_price_rho1^2));
investment_efficiency_std          = sqrt(0.0061^2/(1-investment_efficiency_rho1^2));
labour_tax_std                     = 0.0000;
price_mark_up_std                  = sqrt(0.0042^2/(1-price_mark_up_rho1^2));
wage_mark_up_std                   = sqrt(0.0040^2/(1-wage_mark_up_rho1^2));
inflation_target_std               = sqrt(1.0000^2/(1-inflation_target_rho1^2));
taylor_std                         = sqrt(0.0049^2/(1-taylor_rho1^2));
public_spending_std                = sqrt(0.0055^2/(1-public_spending_rho1^2));
habit_std                          = sqrt(1.0000^2/(1-habit_rho1^2));
preference_std                     = sqrt(1.0000^2/(1-preference_rho1^2));


@#for shock in 1:NumberOfShocks
  @{ExogenousVariables_pnames[shock]}_i_std = 1.000 ; // Useless. Will be updated in the steady state file!     
  @#if (ExogenousVariables_nblags[shock]>0)
    @#for lag in 1:ExogenousVariables_nblags[shock]
      @{ExogenousVariables_pnames[shock]}_ar@{lag} = 0.0000 ; // Useless. Will be updated in the steady state file!
      @{ExogenousVariables_pnames[shock]}_rho@{lag} = @{ExogenousVariables_acorr1_mode[shock]}^@{lag}; 
    @#endfor
  @#endif
@#endfor

FinalGoodLagrangeMultiplier_ss = 1 ;
AveragedRelativePrices_ss = 1 ;
PriceDistorsion_ss = 1 ;
NablaPrice_ss = 1 ;
OptimalRelativePrice_ss = 1 ;
EmploymentAgencyLagrangeMultiplier_ss = 1 ;
RealWageGrowthFactor_ss = 1;
AveragedRelativeWages_ss = 1 ;
OptimalRelativeRealWage_ss = 1 ;
WageDistorsion_ss = 1 ;
NablaWage_ss = 1 ;
TobinQ_ss = 1;
OutputGap_ss = 1 ;
InvestmentCost_ss = 0;
dInvestmentCost_ss = 0;
EfficientInvestmentCost_ss = 0;
dEfficientInvestmentCost_ss = 0;
RealMarginalCost_ss = 1/steady_state_mark_up_f ;
NonOptimizingFirmsPriceGrowth_ss = inflation_target_ss ;
InflationFactor_ss = inflation_target_ss ;
NonOptimizingUnionsWageGrowth_ss = inflation_target_ss ;
ssratio_HouseholdRealWage_RealGrossWage = 1/steady_state_mark_up_s ; 
NominalInterestFactor_ss = steady_state_nominal_interest_factor ;

beta = inflation_target_ss/(risk_premium_ss*NominalInterestFactor_ss)*(1+production_efficiency_growth_ss)^(sigmac);
   
RealInterestFactor_ss = NominalInterestFactor_ss / inflation_target_ss ;  
CapacityUtilizationFactor_ss = capacity_utilization_factor_ss ;
DepreciationRate_ss = depreciation_rate_ss;
CapitalReturnRate_ss = ((1+production_efficiency_growth_ss)^sigmac-beta*(1-depreciation_rate_ss))/(beta*income_tax_ss*capacity_utilization_factor_ss);
dDepreciationRate_ss = CapitalReturnRate_ss*income_tax_ss;

first_derivate_depreciation_rate_ss = dDepreciationRate_ss;

alpha = 1 - labour_tax_ss*steady_state_mark_up_f*steady_state_labour_share;

RealGrossWage_ss = (RealMarginalCost_ss*(alpha/CapitalReturnRate_ss)^alpha)^(1/(1-alpha))*(1-alpha)/labour_tax_ss*production_efficiency_ss;
HouseholdRealWage_ss = ssratio_HouseholdRealWage_RealGrossWage * RealGrossWage_ss;
ssratio_CapitalDemand_HouseholdLabourSupply = labour_tax_ss*RealGrossWage_ss/CapitalReturnRate_ss*alpha/(1-alpha) ;
ssratio_GDP_HouseholdLabourSupply = ssratio_CapitalDemand_HouseholdLabourSupply^alpha * production_efficiency_ss^(1-alpha) ;
ssratio_Investment_GDP = (production_efficiency_growth_ss + depreciation_rate_ss)/capacity_utilization_factor_ss*ssratio_CapitalDemand_HouseholdLabourSupply^(1-alpha)/production_efficiency_ss^(1-alpha) ; 
ssratio_Consumption_GDP = 1 - public_spending_ss - ssratio_Investment_GDP;
labour_supply_ss = HouseholdRealWage_ss/(ssratio_Consumption_GDP*ssratio_GDP_HouseholdLabourSupply) * income_tax_ss * labour_income_tax_ss / consumption_tax_ss /(1-eta/(1+production_efficiency_growth_ss));
HouseholdLabourSupply_ss = household_labour_supply_ss;
LabourDemand_ss = HouseholdLabourSupply_ss;
EmploymentAgencyLabourSupply_ss = HouseholdLabourSupply_ss;
GDP_ss = ssratio_GDP_HouseholdLabourSupply * HouseholdLabourSupply_ss ;
Consumption_ss = ssratio_Consumption_GDP * GDP_ss ;
Investment_ss = ssratio_Investment_GDP * GDP_ss ;
HouseholdLagrangeMultiplier_ss = (1/consumption_tax_ss)*(Consumption_ss*(1-eta/(1+production_efficiency_growth_ss)))^(-sigmac) * exp(labour_supply_ss*(sigmac-1)/(1+sigmal));
CapitalDemand_ss = ssratio_CapitalDemand_HouseholdLabourSupply * HouseholdLabourSupply_ss ;
CapitalStock_ss = (1+production_efficiency_growth_ss)/(production_efficiency_growth_ss+depreciation_rate_ss)*Investment_ss ;

psif = - kimball_curvature_f / thetaf ;
psis = - kimball_curvature_s / thetas ;
xip  = (price_contract_length - 1)/price_contract_length ;
xiw  = (wage_contract_length - 1)/wage_contract_length ;

Z1_ss = RealMarginalCost_ss*HouseholdLagrangeMultiplier_ss*GDP_ss /(1-beta*xip*(1+production_efficiency_growth_ss)^(1-sigmac)) ;
Z2_ss = Z1_ss/RealMarginalCost_ss ;
Z3_ss = Z2_ss ;
H1_ss = HouseholdRealWage_ss*HouseholdLagrangeMultiplier_ss*EmploymentAgencyLabourSupply_ss /(1-beta*xiw*(1+production_efficiency_growth_ss)^(1-sigmac)) ;
H2_ss = H1_ss/ssratio_HouseholdRealWage_RealGrossWage ;
H3_ss = H2_ss ;
ProductionEfficiencyGrowth_ss = (1+production_efficiency_growth_ss) ;
ProductionEfficiencyCycle_ss = production_efficiency_ss ;
ConsumptionTax_ss = consumption_tax_ss ;
LabourIncomeTax_ss = labour_income_tax_ss ;
IncomeTax_ss = income_tax_ss ;
RiskPremium_ss = risk_premium_ss ;
LabourSupplyShock_ss = labour_supply_ss ;
InvestmentRelativePrice_ss = investment_relative_price_ss ;
InvestmentEfficiencyShock_ss = investment_efficiency_ss ;
LabourTax_ss = labour_tax_ss ;
PriceMarkUpShock_ss = price_mark_up_ss ;
WageMarkUpShock_ss = wage_mark_up_ss ;
InflationTarget_ss = inflation_target_ss ;
TaylorShock_ss = taylor_ss ;
PublicSpendingShare_ss = public_spending_ss ;
PublicSpending_ss = GDP_ss * PublicSpendingShare_ss ;
HabitShock_ss = 1.0000;
PreferenceShock_ss = 1.0000;
EfficientConsumption_ss = Consumption_ss ;
EfficientHouseholdLabourSupply_ss = HouseholdLabourSupply_ss ;
EfficientHouseholdLagrangeMultiplier_ss = HouseholdLagrangeMultiplier_ss ;
EfficientInvestment_ss = Investment_ss;
EfficientCapitalStock_ss = CapitalStock_ss;
EfficientDepreciationRate_ss = DepreciationRate_ss;
dEfficientDepreciationRate_ss = dDepreciationRate_ss;
EfficientCapacityUtilizationFactor_ss = CapacityUtilizationFactor_ss;
EfficientCapitalReturnRate_ss = CapitalReturnRate_ss;
EfficientHouseholdRealWage_ss = HouseholdRealWage_ss;
EfficientTobinQ_ss = TobinQ_ss;
EfficientRealInterestFactor_ss = RealInterestFactor_ss;
EfficientLabourDemand_ss = LabourDemand_ss;
EfficientRealMarginalCost_ss = RealMarginalCost_ss;
EfficientGDP_ss = GDP_ss;
EfficientCapitalDemand_ss = CapitalDemand_ss;
EfficientRealGrossWage_ss = RealGrossWage_ss;


model;

	/*
	** HOUSEHOLDS.
	*/


	/* Equation:1:: Household Consumption FOC  */
	(Consumption - eta*HabitShock*Consumption(-1)/ProductionEfficiencyGrowth+log(PreferenceShock))^(-sigmac)
	*exp(LabourSupplyShock*(sigmac-1)/(1+sigmal)*(HouseholdLabourSupply/household_labour_supply_ss)^(1+sigmal))
	- ConsumptionTax*HouseholdLagrangeMultiplier ;

	/* Equation:2:: Household Euler equation  */
	beta*RiskPremium*NominalInterestFactor*ProductionEfficiencyGrowth(1)^(-sigmac)
	*HouseholdLagrangeMultiplier(1)*IncomeTax(1)/InflationFactor(1)
	- HouseholdLagrangeMultiplier*IncomeTax;
	
	/* Equation:3:: Household Labour FOC  */
	(Consumption - eta*HabitShock*Consumption(-1)/ProductionEfficiencyGrowth+log(PreferenceShock))^(1-sigmac)
	*(LabourSupplyShock/household_labour_supply_ss)
	*exp(LabourSupplyShock*(sigmac-1)/(1+sigmal)*(HouseholdLabourSupply/household_labour_supply_ss)^(1+sigmal))
	*(HouseholdLabourSupply/household_labour_supply_ss)^sigmal
	-HouseholdLagrangeMultiplier*IncomeTax*LabourIncomeTax*HouseholdRealWage;
 
	/* Equation:4:: Household Investment FOC  */
	TobinQ*(1-InvestmentCost-Investment/Investment(-1)*ProductionEfficiencyGrowth*dInvestmentCost)
	+beta*HouseholdLagrangeMultiplier(1)/HouseholdLagrangeMultiplier
	*ProductionEfficiencyGrowth(1)^(-sigmac)*TobinQ(1)*InvestmentEfficiencyShock(1)/InvestmentEfficiencyShock
	*(Investment(1)/Investment*ProductionEfficiencyGrowth(1))^2
	*dInvestmentCost(1)
	-InvestmentRelativePrice/InvestmentEfficiencyShock;

	/* Equation:5:: Depreciation rate */
	depreciation_rate_ss
	*exp((CapacityUtilizationFactor-capacity_utilization_factor_ss)*first_derivate_depreciation_rate_ss/depreciation_rate_ss)
	-DepreciationRate;

	/* Equation:6:: First derivate of the depreciation rate */
	first_derivate_depreciation_rate_ss
	*exp((CapacityUtilizationFactor-capacity_utilization_factor_ss)*first_derivate_depreciation_rate_ss/depreciation_rate_ss)
	-dDepreciationRate;

	/* Equation:7:: Household Capacity utilization rate */
	IncomeTax*CapitalReturnRate-TobinQ*dDepreciationRate;

	/* Equation:8:: Household Physical capital FOC */
	beta*HouseholdLagrangeMultiplier(1)/HouseholdLagrangeMultiplier
	*ProductionEfficiencyGrowth(1)^(-sigmac)
	*(TobinQ(1)*(1-DepreciationRate(1))+IncomeTax(1)*CapitalReturnRate(1)*CapacityUtilizationFactor(1))
	-TobinQ;

	/*Equation:9:: Physical capital stock law of motion */
	(1-DepreciationRate)*CapitalStock(-1)/ProductionEfficiencyGrowth
	+InvestmentEfficiencyShock*(1-InvestmentCost)*Investment-CapitalStock;

	/*Equation:10:: Investment cost */
        InvestmentCost = .5*investment_cost_size*(1+production_efficiency_growth_ss)*(1+production_efficiency_growth_ss)
        *(Investment/Investment(-1)*ProductionEfficiencyGrowth/(1+production_efficiency_growth_ss)-1)^2;

	/*Equation:11:: First derivate of the investment cost */
        dInvestmentCost = (Investment/Investment(-1)*ProductionEfficiencyGrowth/(1+production_efficiency_growth_ss)-1)
        *(1+production_efficiency_growth_ss)*investment_cost_size;


	/*
	** PRICES.
	*/


	/*Equation:12:: Price growth factor for non optimizing intermediate firms */
	 InflationTarget^(1-gammap)
	 *InflationFactor(-1)^gammap
	-NonOptimizingFirmsPriceGrowth;

	/*Equation:13:: Factor Price Frontier */
	LabourTax*RealGrossWage*LabourDemand/(CapitalReturnRate*CapitalDemand)
	- (1-alpha)/alpha;

	/*Equation:14:: Marginal cost */
	ProductionEfficiencyCycle^(alpha-1)
	*(CapitalReturnRate/alpha)^alpha
	*(LabourTax*RealGrossWage/(1-alpha))^(1-alpha)
	-RealMarginalCost;

	/*Equation:15:: Relative price of an optimizing intermediate firm */
	thetaf*(1+psif)/(thetaf*(1+psif)-1)*(Z1/Z2)
	+psif/(thetaf*(1+psif)-1)*OptimalRelativePrice^(1+(1+psif)*thetaf)*Z3/Z2
	-OptimalRelativePrice;

	/*Equation:16:: Lagrange multiplier associated to technological constraint of the final good representative firm */ 
	(1-xip)*OptimalRelativePrice^(1-thetaf*(1+psif))
	+xip*(NonOptimizingFirmsPriceGrowth/InflationFactor)^(1-thetaf*(1+psif))
	*FinalGoodLagrangeMultiplier(-1)^(1-thetaf*(1+psif))
	-FinalGoodLagrangeMultiplier^(1-thetaf*(1+psif));	
	
	/*Equation:17:: Z1 (relative price equation) */	
	HouseholdLagrangeMultiplier*RealMarginalCost*FinalGoodLagrangeMultiplier^(thetaf*(1+psif))*GDP
	+beta*xip*ProductionEfficiencyGrowth(1)^(1-sigmac)
	*(InflationFactor(1)/NonOptimizingFirmsPriceGrowth)^((1+psif)*thetaf)*Z1(1)
	-Z1;

	/*Equation:18:: Z2 (relative price equation) */	
	HouseholdLagrangeMultiplier*PriceMarkUpShock*FinalGoodLagrangeMultiplier^(thetaf*(1+psif))*GDP
	+beta*xip*ProductionEfficiencyGrowth(1)^(1-sigmac)
	*(InflationFactor(1)/NonOptimizingFirmsPriceGrowth)^((1+psif)*thetaf-1)*Z2(1)
	-Z2;

	/*Equation:19:: Z3 (relative price equation) */	
	HouseholdLagrangeMultiplier*PriceMarkUpShock*GDP
	+beta*xip*ProductionEfficiencyGrowth(1)^(1-sigmac)
	*NonOptimizingFirmsPriceGrowth/InflationFactor(1)*Z3(1)
	-Z3;
	
	/*Equation:20:: Average of relative prices */
	(1-xip)*OptimalRelativePrice
	+xip*NonOptimizingFirmsPriceGrowth/InflationFactor*AveragedRelativePrices(-1)
	-AveragedRelativePrices;
	
	/*Equation:21:: Agregate price */
	psif*AveragedRelativePrices/(1+psif)
	+FinalGoodLagrangeMultiplier/(1+psif)
	-1;

	/*Equation:22:: Price Distorsion */
	psif/(1+psif)
	+NablaPrice/(1+psif)*FinalGoodLagrangeMultiplier^(thetaf*(1+psif))
	-PriceDistorsion;
	
	/*Equation:23:: nabla (recursive latent variable used in price distorsion equation) */
	(1-xip)*OptimalRelativePrice^(-(1+psif)*thetaf)
	+xip*NablaPrice(-1)*(NonOptimizingFirmsPriceGrowth/InflationFactor)^(-thetaf*(1+psif))
	-NablaPrice;


	/*
	** WAGES.
	*/


	/*Equation:24:: Wage growth factor of the non optimizing firms */
	InflationFactor^gammaw*InflationTarget^(1-gammaw)
	-NonOptimizingUnionsWageGrowth;

	/*Equation:25:: Real wage inflation factor */
	RealGrossWage/RealGrossWage(-1)-RealWageGrowthFactor;
	
	/*Equation:26:: Relative wage of an optimizing union */ 
	thetas*(1+psis)/(thetas*(1+psis)-1)*H1/H2
	+psis/(thetas*(1+psis)-1)*OptimalRelativeRealWage^(1+(1+psis)*thetas)*H3/H2
	-OptimalRelativeRealWage;

	/*Equation:27:: Lagrange multiplier associated to the employment agency */ 
	(1-xiw)*OptimalRelativeRealWage^(1-thetas*(1+psis))
	+xiw*(NonOptimizingUnionsWageGrowth/(RealWageGrowthFactor*InflationFactor))^(1-thetas*(1+psis))
	*EmploymentAgencyLagrangeMultiplier(-1)^(1-thetas*(1+psis))
	-EmploymentAgencyLagrangeMultiplier^(1-thetas*(1+psis));	


	/*Equation:28:: H1 (relative wage equation) */
	HouseholdLagrangeMultiplier*HouseholdRealWage*EmploymentAgencyLagrangeMultiplier^(thetas*(1+psis))*EmploymentAgencyLabourSupply
	+beta*xiw*ProductionEfficiencyGrowth(1)^(1-sigmac)
	*(RealWageGrowthFactor(1)*InflationFactor(1)/NonOptimizingUnionsWageGrowth)^((1+psis)*thetas)*H1(1)
	-H1;

	/*Equation:29:: H2 (relative wage equation) */
	HouseholdLagrangeMultiplier*WageMarkUpShock*RealGrossWage
	*EmploymentAgencyLagrangeMultiplier^(thetas*(1+psis))*EmploymentAgencyLabourSupply
	+beta*xiw*ProductionEfficiencyGrowth(1)^(1-sigmac)
	*(RealWageGrowthFactor(1)*InflationFactor(1)/NonOptimizingUnionsWageGrowth)^((1+psis)*thetas-1)*H2(1)
	-H2;

	/*Equation:30:: H3 (relative wage equation) */	
	HouseholdLagrangeMultiplier*WageMarkUpShock*RealGrossWage*EmploymentAgencyLabourSupply
	+beta*xiw*ProductionEfficiencyGrowth(1)^(1-sigmac)
	*NonOptimizingUnionsWageGrowth/(InflationFactor(1)*RealWageGrowthFactor(1))*H3(1)
	-H3;

	/*Equation:31:: Average of relative wages */
	(1-xiw)*OptimalRelativeRealWage
	+xiw*NonOptimizingUnionsWageGrowth/(RealWageGrowthFactor*InflationFactor)*AveragedRelativeWages(-1)
	-AveragedRelativeWages;

	/*Equation:32:: Agregate Wage */
	psis*AveragedRelativeWages/(1+psis)
	+EmploymentAgencyLagrangeMultiplier/(1+psis)
	-1;

	/*Equation:33:: Wage Distorsion */
	psis/(1+psis)
	+NablaWage/(1+psis)*EmploymentAgencyLagrangeMultiplier^(thetas*(1+psis))
	-WageDistorsion;
	
	/*Equation:34:: nabla (recursive latent variable used in wage distorsion equation) */
	(1-xiw)*OptimalRelativeRealWage^(-(1+psis)*thetas)
	+xiw*NablaWage(-1)*(NonOptimizingUnionsWageGrowth/(RealWageGrowthFactor*InflationFactor))^(-thetas*(1+psis))
	-NablaWage;


	/*
	** MONETARY AUTHORITY & GOVERNMENT
	*/


	/*Equation:35:: Taylor rule */
          NominalInterestFactor(-1)^nominal_interest_rate_smoothing
	  *(
	  steady_state_nominal_interest_factor
	  *(InflationFactor(-1)/InflationTarget)^elasticity_of_nominal_interest_rate_to_inflation
	  *OutputGap^elasticity_of_nominal_interest_rate_to_output_gap
	  *(InflationFactor/InflationTarget*InflationTarget(-1)/InflationFactor(-1))^elasticity_of_nominal_interest_rate_to_inflation_growth
	  *(OutputGap/OutputGap(-1))^elasticity_of_nominal_interest_rate_to_output_gap_growth
	  )^(1-nominal_interest_rate_smoothing)
	  *TaylorShock
	  - NominalInterestFactor;         


	/*Equation:36:: Output gap */
	@#if (efficient_block==1)
	  GDP/EfficientGDP
	  -OutputGap;
	@#endif  
	@#if (efficient_block==0)
	  GDP/ssGDP
	  -OutputGap;
	@#endif

	/*Equation:37:: Public Spending */
	PublicSpendingShare * GDP - PublicSpending;
	

	/*
	** MARKETS
	*/


	/*Equation:38:: Physical capital market equilibrium */
	CapacityUtilizationFactor*CapitalStock(-1)/ProductionEfficiencyGrowth - CapitalDemand ;

	/*Equation:39:: Relation between household labour supply and employment agency labour supply */
	HouseholdLabourSupply/WageDistorsion - EmploymentAgencyLabourSupply;

	/*Equation:40:: Labour market equilibrium */
	EmploymentAgencyLabourSupply - LabourDemand;

	/*Equation:41:: Relation between GDP and the sum of produced intermediate goods */
	CapitalDemand^alpha * (ProductionEfficiencyCycle*LabourDemand)^(1-alpha) / PriceDistorsion - GDP;

	/*Equation:42:: Final good market equilibrium */
	PublicSpending + Consumption + InvestmentRelativePrice*Investment
	- PriceMarkUpShock*GDP - (1-WageMarkUpShock)*RealGrossWage*LabourDemand;
	
	/* 
	** EQUATIONS FOR THE SHOCKS (Equations 43 to 57).
	*/
        @#for shock in 1:NumberOfShocks
          exp(@{ExogenousVariables_pnames[shock]}_i_std*@{ExogenousVariables_inames[shock]})
          @#if (shock==1)
            @#if (ExogenousVariables_nblags[shock]>0)
              @#for lag in 1:ExogenousVariables_nblags[shock]
                * (@{ExogenousVariables_vnames[shock]}(-@{lag})/(1+@{ExogenousVariables_pnames[shock]}_ss))^@{ExogenousVariables_pnames[shock]}_ar@{lag} 
              @#endfor
            @#endif
          @#else
            @#if (ExogenousVariables_nblags[shock]>0)
              @#for lag in 1:ExogenousVariables_nblags[shock]
                * (@{ExogenousVariables_vnames[shock]}(-@{lag})/@{ExogenousVariables_pnames[shock]}_ss)^@{ExogenousVariables_pnames[shock]}_ar@{lag} 
              @#endfor
            @#endif
          @#endif 
          @#if (shock==1)
            - @{ExogenousVariables_vnames[shock]}/(1+@{ExogenousVariables_pnames[shock]}_ss)
          @#else
            - @{ExogenousVariables_vnames[shock]}/@{ExogenousVariables_pnames[shock]}_ss
          @#endif
          ;
        @#endfor

	@#if (efficient_block==1)
	/*
	** EQUATIONS FOR THE EFFICIENT VARIABLES.
	*/
		
	
	/* Equation:58:: (Efficient) Household Consumption FOC */ 
	(EfficientConsumption - eta*HabitShock*EfficientConsumption(-1)/ProductionEfficiencyGrowth+log(PreferenceShock))^(-sigmac)
	*exp(LabourSupplyShock*(sigmac-1)/(1+sigmal)*(EfficientHouseholdLabourSupply/household_labour_supply_ss)^(1+sigmal))
	- ConsumptionTax*EfficientHouseholdLagrangeMultiplier ;

	/* Equation:59:: (Efficient) Household Euler equation  */
	beta*RiskPremium*EfficientRealInterestFactor*ProductionEfficiencyGrowth(1)^(-sigmac)
	*EfficientHouseholdLagrangeMultiplier(1)*IncomeTax(1)
	- EfficientHouseholdLagrangeMultiplier*IncomeTax;
	
	/* Equation:60:: (Efficient) Household Labour FOC  */
	(EfficientConsumption - eta*HabitShock*EfficientConsumption(-1)/ProductionEfficiencyGrowth+log(PreferenceShock))^(1-sigmac)
	*(LabourSupplyShock/household_labour_supply_ss)
	*exp(LabourSupplyShock*(sigmac-1)/(1+sigmal)*(EfficientHouseholdLabourSupply/household_labour_supply_ss)^(1+sigmal))
	*(EfficientHouseholdLabourSupply/household_labour_supply_ss)^sigmal
	-EfficientHouseholdLagrangeMultiplier*IncomeTax*LabourIncomeTax*EfficientHouseholdRealWage;
 
	/* Equation:61:: (Efficient) Household Investment FOC  */
	EfficientTobinQ*(1-EfficientInvestmentCost-EfficientInvestment/EfficientInvestment(-1)*ProductionEfficiencyGrowth*dEfficientInvestmentCost)
	+beta*EfficientHouseholdLagrangeMultiplier(1)/EfficientHouseholdLagrangeMultiplier
	*ProductionEfficiencyGrowth(1)^(-sigmac)*EfficientTobinQ(1)*InvestmentEfficiencyShock(1)/InvestmentEfficiencyShock
	*(EfficientInvestment(1)/EfficientInvestment*ProductionEfficiencyGrowth(1))^2
	*dEfficientInvestmentCost(1)-InvestmentRelativePrice/InvestmentEfficiencyShock;

	/* Equation:62:: (Efficient) Depreciation rate */
	depreciation_rate_ss
	*exp((EfficientCapacityUtilizationFactor-capacity_utilization_factor_ss)*first_derivate_depreciation_rate_ss/depreciation_rate_ss)
	-EfficientDepreciationRate;

	/* Equation:63:: (Efficient) First derivate of the depreciation rate */
	first_derivate_depreciation_rate_ss
	*exp((EfficientCapacityUtilizationFactor-capacity_utilization_factor_ss)*first_derivate_depreciation_rate_ss/depreciation_rate_ss)
	-dEfficientDepreciationRate;

	/* Equation:64:: (Efficient) Household Capacity utilization rate */
	IncomeTax*EfficientCapitalReturnRate-EfficientTobinQ*dEfficientDepreciationRate;

	/* Equation:65:: (Efficient) Household Physical capital FOC */
	beta*EfficientHouseholdLagrangeMultiplier(1)/EfficientHouseholdLagrangeMultiplier
	*ProductionEfficiencyGrowth(1)^(-sigmac)
	*(EfficientTobinQ(1)*(1-EfficientDepreciationRate(1))+IncomeTax(1)*EfficientCapitalReturnRate(1)*EfficientCapacityUtilizationFactor(1))
	-EfficientTobinQ;

	/*Equation:66:: (Efficient) Physical capital stock law of motion */
	(1-EfficientDepreciationRate)*EfficientCapitalStock(-1)/ProductionEfficiencyGrowth
	+InvestmentEfficiencyShock*(1-EfficientInvestmentCost)*EfficientInvestment
	-EfficientCapitalStock;

	/*Equation:67:: (Efficient) Factor Price Frontier */
	LabourTax*EfficientRealGrossWage*EfficientLabourDemand/(EfficientCapitalReturnRate*EfficientCapitalDemand)
	- (1-alpha)/alpha;

	/*Equation:68:: (Efficient) Marginal cost */
	ProductionEfficiencyCycle^(alpha-1)
	*(EfficientCapitalReturnRate/alpha)^alpha
	*(LabourTax*EfficientRealGrossWage/(1-alpha))^(1-alpha)
	-EfficientRealMarginalCost;

	/*Equation:69:: (Efficient) Price decision */
	thetaf*(1+psif)/(thetaf*(1+psif)-1)*EfficientRealMarginalCost
	+psif/(thetaf*(1+psif)-1)
	-1;

	/*Equation:70:: (Efficient) Wage decision */ 
	thetas*(1+psis)/(thetas*(1+psis)-1)*EfficientHouseholdRealWage/EfficientRealGrossWage
	+psis/(thetas*(1+psis)-1)
	-1;

	/*Equation:71:: (Efficient) Labour market equilibrium */
	EfficientLabourDemand - EfficientHouseholdLabourSupply;

	/*Equation:72:: (Efficient) Physical capital market equilibrium */
	EfficientCapacityUtilizationFactor*EfficientCapitalStock(-1)/ProductionEfficiencyGrowth - EfficientCapitalDemand ;	

	/*Equation:73:: (Efficient) Final good market equilibrium */
	EfficientConsumption + InvestmentRelativePrice*EfficientInvestment 
	- (1-PublicSpendingShare)*EfficientGDP;

	/*Equation:74:: (Efficient) Relation between GDP and the sum of produced intermediate goods */
	EfficientCapitalDemand^alpha * (ProductionEfficiencyCycle*EfficientLabourDemand)^(1-alpha) - EfficientGDP;

        /*Equation:75:: (Efficient) Investment cost */
        .5*investment_cost_size*(1+production_efficiency_growth_ss)*(1+production_efficiency_growth_ss)
        *(EfficientInvestment/EfficientInvestment(-1)*ProductionEfficiencyGrowth/(1+production_efficiency_growth_ss)-1)^2
        -EfficientInvestmentCost;

        /*Equation:76:: (Efficient) First derivate of the investment cost */
        (EfficientInvestment/EfficientInvestment(-1)*ProductionEfficiencyGrowth/(1+production_efficiency_growth_ss)-1)
        *(1+production_efficiency_growth_ss)*investment_cost_size
        - dEfficientInvestmentCost;

	@#endif

end;

initval;
    /* Households */
    Consumption = Consumption_ss;
    HouseholdLabourSupply = HouseholdLabourSupply_ss;
    HouseholdLagrangeMultiplier = HouseholdLagrangeMultiplier_ss;
    Investment = Investment_ss;
    CapitalStock = CapitalStock_ss;
    DepreciationRate = DepreciationRate_ss;
    dDepreciationRate = dDepreciationRate_ss;
    InvestmentCost = InvestmentCost_ss;
    dInvestmentCost = dInvestmentCost_ss;
    CapacityUtilizationFactor = CapacityUtilizationFactor_ss;
    CapitalReturnRate = CapitalReturnRate_ss;
    HouseholdRealWage = HouseholdRealWage_ss;
    TobinQ = TobinQ_ss;
    /* Prices */
    RealGrossWage = RealGrossWage_ss;
    LabourDemand = LabourDemand_ss;
    CapitalDemand = CapitalDemand_ss;
    RealMarginalCost = RealMarginalCost_ss;
    OptimalRelativePrice = OptimalRelativePrice_ss;
    Z1 = Z1_ss;
    Z2 = Z2_ss;
    Z3 = Z3_ss;
    GDP = GDP_ss;
    FinalGoodLagrangeMultiplier = FinalGoodLagrangeMultiplier_ss;
    NonOptimizingFirmsPriceGrowth = NonOptimizingFirmsPriceGrowth_ss;
    AveragedRelativePrices = AveragedRelativePrices_ss;
    PriceDistorsion = PriceDistorsion_ss;
    NablaPrice = NablaPrice_ss;
    InflationFactor = InflationFactor_ss;
    /* Wages */
    RealWageGrowthFactor = RealWageGrowthFactor_ss;
    AveragedRelativeWages = AveragedRelativeWages_ss;
    OptimalRelativeRealWage = OptimalRelativeRealWage_ss;
    H1 = H1_ss;
    H2 = H2_ss;
    H3 = H3_ss;
    EmploymentAgencyLagrangeMultiplier = EmploymentAgencyLagrangeMultiplier_ss;
    EmploymentAgencyLabourSupply = EmploymentAgencyLabourSupply_ss;
    NonOptimizingUnionsWageGrowth = NonOptimizingUnionsWageGrowth_ss;
    WageDistorsion = WageDistorsion_ss;
    NablaWage = NablaWage_ss;	    
    /* Monetary authority and Government */
    NominalInterestFactor = NominalInterestFactor_ss;
    OutputGap = OutputGap_ss;
    PublicSpending = PublicSpending_ss;
    /* Efficient variables (model without nominal rigidities) */    
    @#if (efficient_block==1)
      EfficientConsumption = EfficientConsumption_ss;
      EfficientHouseholdLabourSupply = EfficientHouseholdLabourSupply_ss;
      EfficientHouseholdLagrangeMultiplier = EfficientHouseholdLagrangeMultiplier_ss;
      EfficientInvestment = EfficientInvestment_ss;
      EfficientCapitalStock = EfficientCapitalStock_ss;
      EfficientDepreciationRate = EfficientDepreciationRate_ss;
      dEfficientDepreciationRate = dEfficientDepreciationRate_ss;
      EfficientInvestmentCost = EfficientInvestmentCost_ss;
      dEfficientInvestmentCost = dEfficientInvestmentCost_ss;
      EfficientCapacityUtilizationFactor = EfficientCapacityUtilizationFactor_ss;
      EfficientCapitalReturnRate = EfficientCapitalReturnRate_ss;
      EfficientHouseholdRealWage = EfficientHouseholdRealWage_ss;
      EfficientTobinQ = EfficientTobinQ_ss;
      EfficientRealInterestFactor = EfficientRealInterestFactor_ss;
      EfficientLabourDemand = EfficientLabourDemand_ss;
      EfficientRealMarginalCost = EfficientRealMarginalCost_ss;
      EfficientGDP = EfficientGDP_ss;
      EfficientCapitalDemand = EfficientCapitalDemand_ss;
      EfficientRealGrossWage = EfficientRealGrossWage_ss;
    @#endif
    /* Shocks */
    @#for shock in 1:NumberOfShocks
      @{ExogenousVariables_inames[shock]} = 0.0;
    @#endfor
    @{ExogenousVariables_vnames[shock]} = 1+@{ExogenousVariables_pnames[shock]}_ss ;
    @#for shock in 2:NumberOfShocks
      @{ExogenousVariables_vnames[shock]} = @{ExogenousVariables_pnames[shock]}_ss;   
    @#endfor
end;

steady;

resid(1);
check;

shocks;
var EfficiencyGrowthInnovation        = .001;
var EfficiencyCycleInnovation         = .005;
var RiskPremiumInnovation             = .003;
/*
var ConsumptionTaxInnovation          = .0000001;
var LabourIncomeTaxInnovation         = .0000001;
var IncomeTaxInnovation               = .0000001;
var LabourSupplyInnovation            = .0000001;
var InvestmentRelativePriceInnovation = .0000001;
var InvestmentEfficiencyInnovation    = .0000001;
var LabourTaxInnovation               = .0000001;
var PriceMarkUpInnovation             = .0000001;
var WageMarkUpInnovation              = .0000001;
var InflationTargetInnovation         = .0000001;
var TaylorInnovation                  = .0000001;
var PublicSpendingShareInnovation     = .0000001; 
var HabitInnovation                   = .0000001; 
var PreferenceInnovation              = .0000001; 
*/
end;

stoch_simul(order=1,irf=0,noprint,periods=2000);

plot(OutputGap);
