Run Time Error 5 Invalid Procedure or Error Argument - Repost

Status
Not open for further replies.

Ed Song

Board Regular
Joined
Sep 1, 2014
Messages
90
Since this problem remains unsolved, I want to retry this post to see if anyone can find the problem. I have a run time Error 5, Invalid Call Procedure or Error Argument. The offending code is:

Output_t1 = GrowthFactor ^ (Period_Length) * (Output_t0 + FactorProductivity * (1 - Damages_Production_t1) * _
(1 - AbatementCost_Production) * (CapitalStock_t1 - CapitalStock_t0) ^ Share_K_Capital * _
(Labor_t0 ^ Share_Labor))

Specifically, the program does not like the term CapitalStock_t1 - CapitalStock_t0. I've tested every variable and every combination of variables, and the program only dislikes the term above, although once in awhile I'll get another run time 5 error in another statement. But generally, if I have CapitalStock_t1 or just CapitalStock_t0 in the statement, the program runs.

If I use the term Output_t1 = CapitalStock_t1 - CapitalStock_t0 the program does not work. But it will work if I use Output_t1 = CapitalStock_t1 or Output_t1 = CapitalStock_t0. All combinations without the term CapitalStock_t1 - CapitalStock_t0 does work.

I'm getting desperate. If anyone can help me, please help. I don't want to abandon this project. I've halted my project for two days over this problem.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Maybe you should post all the code so someone may be able to test !
Are all the variables dimmed ?
Are all the named ranges that require a calculation actually numbers and none of the calculations contain some Text values, thereby causing an error ??
Have you considered breaking down the larger calc into smaller packets to ensure the problem lies where you think it does ??
 
Upvote 0
Maybe you should post all the code so someone may be able to test !
Are all the variables dimmed ?
Are all the named ranges that require a calculation actually numbers and none of the calculations contain some Text values, thereby causing an error ??
Have you considered breaking down the larger calc into smaller packets to ensure the problem lies where you think it does ??

Thank Michael, here is my entire code:

Code:
Option Explicit


'Base Model Program. Emission control variables are set equal to zero.


'This program is designed to simulate possible climate change outcomes.
'Although human capital is important, we will not test human capital in this research.




Sub Main()




'Declaration of Variables


'Time Period Length
    Dim Period_Length
    
'Income Parameter
    Dim Discount_Factor As Single
    Dim Depreciation_K As Double
    Dim MU_Elasticity As Double
    Dim Share_K_Capital As Double
    Dim Share_Labor As Double
    Dim Share_H_Capital As Double
    Dim FactorProductivity As Double
    
'Abatement Cost Parameters
    Dim Proportional_Consumption_Control As Double
    Dim Exponent_Consumption_Control As Double
    Dim Proportional_Production_Control As Double
    Dim Exponent_Production_Control As Double
    Dim AbatementCost_Consumption As Double
    Dim AbatementCost_Production As Double
    
'Carbon Cycle Variables
    Dim Retention_Rate As Double
    Dim Climate_Sensitivity As Double
    Dim CO2_Level_t0 As Double
    Dim CO2_Equilibrium_Fraction_Atm As Double
    Dim CO2_Perm_Fraction As Double
    Dim CO2_Equilibrium_Fraction_Bio_Ocean As Double
    Dim CO2_TransferRate_to_Bio_Ocean As Double
    Dim CO2_TransferRate_to_Atm As Double
    Dim New_CO2_Equilibrium_t0 As Double
    
'Carbon Dioxide - Temperature Relationship
    Dim Forcing_t0 As Double
    Dim ClimateSensitivity As Double
    Dim ClimateSensitivity_Lambda As Double
    Dim Lambda As Double
    Dim ClimateSensitivityParameter_b1 As Double
    Dim ClimateSensitivityParameter_b2 As Double
    Dim TemperatureDeviation As Double
    Dim Temperature_Critical As String
    Dim Temperature_Critical_Max As Double
    Dim SKI_Limit_Temp As Double
    Dim CO2_SKI As Double
    Dim Switch As Integer
    
'Damages
    Dim Proportional_Constant_Temperature_Y As Double
    Dim Exponent_Constant_Temperature_Y As Double
    Dim Proportional_Constant_Temperature_K As Double
    Dim Exponent_Constant_Temperature_K As Double
    Dim Proportional_Constant_Temperature_U As Double
    Dim Exponent_Constant_Temperature_U As Double
    Dim Survivability_Function_t0 As Double
    
'Economic Initial Condition Variables
    Dim Output_t0 As Double
    Dim CapitalStock_t0 As Double
    Dim Consumption_t0 As Double
    Dim Investment_t0 As Double
    Dim Government_t0 As Double
    Dim Dep_k As Double
    
    Dim Labor_t0 As Double
    Dim Share_Consumption As Double
    Dim Share_Investment As Double
    Dim Share_Government As Double
    
'Physical Initial Equilibrium Variables
    Dim CO2_Equilibrium As Double
    Dim C02_Level_t0 As Double
    Dim Temp_t0 As Double
    Dim Retained_Emissions As Double
    Dim Total_Emissions As Double
    Dim Energy_Usage_Total As Double
    Dim Energy_Usage_Consumption As Double
    Dim Energy_Usage_Production As Double
    Dim Energy_to_Consumption_Ratio As Double
    Dim Energy_to_Production_Ratio As Double
    Dim EC_to_EY_Ratio As Double
    Dim Emissions_Consumption_Ratio As Double
    Dim Emissions_Output_Ratio As Double
    
    Dim Retention_Ratio As Double
    Dim Damages_Utility_t0 As Double
    Dim Damages_Production_t0 As Double
    Dim Damages_CapitalStock_t0 As Double
    Dim Damages_Y_Composite_t0 As Double
    Dim Damages_Composite_t0 As Double
    
'Control Variables
    Dim ReductionRate_Production As Double
    Dim ReductionRate_Consumption As Double
    Dim Share_Utility_Damage As Double
    Dim Share_Production_Damage As Double
    Dim Share_CapitalStock_Damage As Double
    Dim Temp_Max As Double
    Dim CO2_Ratio_Critical
    Dim DeadWtLoss_C As Double
    
'Utility Index
    Dim Raw_Utility_Index_t0 As Double
    Dim Utility_Normalization_Factor As Double
    Dim Utility_Index_t0 As Double
    Dim Welfare_t0 As Double


'Charts and Graph Variables Declared.
    Dim Output_t1 As Double
    Dim CapitalStock_t1 As Double
    Dim Capital_t1 As Double
    Dim Consumption_t1 As Double
    Dim Government_t1 As Double
    Dim Investment_t1 As Double
    Dim TotalDeadWtLoss_t1 As Double
    Dim Energy_Usage_Consumption_t1 As Double
    Dim Energy_Usage_Production_t1 As Double
    Dim Energy_Usage_t1 As Double
    Dim AtmoEmissions_t1 As Double
    Dim CO2_Level_t1 As Double
    Dim CO2_Transient_t1 As Double
    Dim New_CO2_Equilibrium_t1 As Double
    Dim Temp_t1 As Double
    Dim Damages_Utility_t1 As Double
    Dim Damages_CapitalStock_t1 As Double
    Dim Damages_Production_t1 As Double
    Dim Damages_Y_Composite_t1 As Double
    Dim Damages_Composite_t1 As Double
    Dim Survivability_Function_t1 As Double
    Dim Utility_Index_t1 As Double
    Dim Welfare_t1 As Double
      
'Set Period Length
    Period_Length = Sheets(1).Range("K79")
    
'Set Discount Factor
    Discount_Factor = Sheets(1).Range("K87")


'Set Parameters
    Dep_k = Sheets(1).Range("K6")
    FactorProductivity = Sheets(1).Range("K45")
    Proportional_Consumption_Control = Sheets(1).Range("K12")
    Exponent_Consumption_Control = Sheets(1).Range("K13")
    Proportional_Production_Control = Sheets(1).Range("K14")
    Exponent_Production_Control = Sheets(1).Range("K15")
    Share_K_Capital = Sheets(1).Range("K8")
    Share_Labor = Sheets(1).Range("K9")
    MU_Elasticity = Sheets(1).Range("K7")
    Temp_Max = Sheets(1).Range("K80")


'Set Policy
    ReductionRate_Production = Sheets(1).Range("K77")
    ReductionRate_Consumption = Sheets(1).Range("K78")
      
    Call Initial_EconVariable(Output_t0, Share_Consumption, Share_Investment, Share_Government, _
                              Consumption_t0, Investment_t0, Government_t0)
        'Calculate initial economic conditions
                              
        'Print calulated values.
            Sheets(1).Cells(47, 11) = Consumption_t0
            Sheets(1).Cells(48, 11) = Investment_t0
            Sheets(1).Cells(49, 11) = Government_t0
        
    Call Initial_Emissions(Retained_Emissions, CO2_Level_t0, CO2_Equilibrium, CO2_Equilibrium_Fraction_Atm, _
                            CO2_TransferRate_to_Atm, Retention_Rate, Total_Emissions)
        'Calculate Emissions of Atmospheric CO2 to Consumption and Output Ratios.
    
        'Print calculated values.
            Sheets(1).Cells(59, 11) = Retained_Emissions
            Sheets(1).Cells(60, 11) = Total_Emissions
    
    Call EnergyUsage(Energy_Usage_Total, Energy_Usage_Consumption, Energy_Usage_Production)
         'Calculate Energy Usage
                 
        'Print calculated values.
            Sheets(1).Cells(63, 11) = Energy_Usage_Consumption
            Sheets(1).Cells(64, 11) = Energy_Usage_Production
           
    Call Energy_Mass_Ratios(Energy_to_Consumption_Ratio, Energy_to_Production_Ratio, EC_to_EY_Ratio, _
                        Emissions_Consumption_Ratio, Emissions_Output_Ratio)
        'Important Ratios to convert energy usage into emissions of CO2
    
        'Print calculated values.
            Sheets(1).Cells(67, 11) = EC_to_EY_Ratio
            Sheets(1).Cells(65, 11) = Energy_to_Consumption_Ratio
            Sheets(1).Cells(66, 11) = Energy_to_Production_Ratio
            Sheets(1).Cells(68, 11) = Emissions_Consumption_Ratio
            Sheets(1).Cells(69, 11) = Emissions_Output_Ratio
    
    Call Forcing(Forcing_t0)
        'Calculate Initial Forcing
 
        'Print calculated value.
            Sheets(1).Cells(57, 11) = Forcing_t0
        
    Call NewEquilibrium(New_CO2_Equilibrium_t0)
        'Calculate new CO2 equilibrium level. As a simplification, assume emissions mix so that the long run equilibrium fraction of CO2 remaining in the
        'atmosphere times new emissions plus the old equilibrium level equals the new long run equilibrium level.
  
        'Print calulated value.
            Sheets(1).Cells(56, 11) = New_CO2_Equilibrium_t0
        
        
    Call Temperature(ClimateSensitivity_Lambda, ClimateSensitivityParameter_b1, Lambda, _
                    Temperature_Critical_Max, CO2_SKI, SKI_Limit_Temp, ClimateSensitivityParameter_b2, Temp_t0)
        'Calculate Temperature Deviation. This is a longer calculation.


        'Print calculated values.
            Sheets(1).Cells(25, 11) = ClimateSensitivity_Lambda
            Sheets(1).Cells(26, 11) = ClimateSensitivityParameter_b1
            Sheets(1).Cells(82, 11) = CO2_SKI
            Sheets(1).Cells(27, 11) = ClimateSensitivityParameter_b2
            Sheets(1).Cells(58, 11) = Temp_t0
        
    Call Damages(Proportional_Constant_Temperature_U, Exponent_Constant_Temperature_U, Damages_Utility_t0, _
                Proportional_Constant_Temperature_Y, Exponent_Constant_Temperature_Y, Damages_Production_t0, _
                Proportional_Constant_Temperature_K, Exponent_Constant_Temperature_K, Damages_CapitalStock_t0, _
                Damages_Y_Composite_t0, Damages_Composite_t0)
        'Calculate the five types of damages; damages to production, capital stock, utility and the composite damages to production _
        'and utility.


        
        'Print calculated values.
            Sheets(1).Cells(70, 11) = Damages_Utility_t0
            Sheets(1).Cells(71, 11) = Damages_Production_t0
            Sheets(1).Cells(72, 11) = Damages_CapitalStock_t0
            Sheets(1).Cells(73, 11) = Damages_Y_Composite_t0
            Sheets(1).Cells(74, 11) = Damages_Composite_t0
    
    Call AbatementCosts(AbatementCost_Production, AbatementCost_Consumption, DeadWtLoss_C)
        'Compute abatement costs
        
            'Print calculated values.
            Sheets(1).Cells(83, 11) = AbatementCost_Production
            Sheets(1).Cells(84, 11) = AbatementCost_Consumption
            Sheets(1).Cells(85, 11) = DeadWtLoss_C
     
    Call Survivability(Survivability_Function_t0)
        'Calculate Survivability Probability Function
        
        'Print calculated value.
        Sheets(1).Cells(75, 11) = Survivability_Function_t0
     


    Call Initial_CapitalStock(CapitalStock_t0)
        'Calculate Initial Labor
        
        'Print calculated value.
        Sheets(1).Cells(41, 11) = CapitalStock_t0
        
    Call Initial_Labor(Labor_t0)
        'Calculate steady state labor supply.
        
        'Print calculated value.
        Sheets(1).Cells(46, 11) = Labor_t0
        
    Call UtilityIndex(Utility_Index_t0, Welfare_t0, Utility_Normalization_Factor)
    'Initial Utility Index
    
    'Print output
    Sheets(1).Cells(86, 11) = Utility_Index_t0
    Sheets(1).Cells(86, 12) = Welfare_t0
   
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Future values can now be calculated. Since we know what investment was in the initial period, we can calulate what was the new amount of capital added
'to the capital stock. Unfortunately, we have a nonlinear problem because there is a simultaneity cause and effect between damages and output. Output
'causes damages, and damgages reduces output. Thus we must do an iteration. First, we calculate the economic variables assuming last periods damages.
'Then we calculate an implied damages and redo the calculation until convergence of a solution occurs. We do an energy balance on the initial output and
'consumption spending and calculate a new emissions. With the new emissions calculated, we then do a mass balance of CO2 in the atmosphere and
'calculate Damages. With damages calculated, we know the new capital stock level, then can calculate new income. With the new income, we can now
'calculate consumption, investment and government spending assuming constant shares. Then we repeat until 100 periods pass.


'Declare t1 variables not yet declared.
    
    Dim AtmoEmissions_Consumption_t1 As Double
    Dim AtmoEmissions_Output_t1 As Double
    Dim Forcing_t1 As Double
    Dim Raw_Utility_Index_t1 As Double
   
    'Declare growth rates
    Dim GrowthFactor As Double
    
    GrowthFactor = Sheets(1).Range("K5")


'Begin Outer Loop XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX End Outer Loop
'The outerloop is the time loop. After variables for a time period is calculated, the program exits the inner loop into the outerloop to update the
'time period.
    
 'Set Counter
 Dim t As Long
 t = 1
 
Do Until t = 102


'First the economy flatlines (dies) if the survivability function is zero.


If Survivability_Function_t0 = 0 Then
    Output_t1 = 0
    CapitalStock_t1 = 0
    Consumption_t1 = 0
    Investment_t1 = 0
    Government_t1 = 0
    TotalDeadWtLoss_t1 = 0
    Energy_Usage_Consumption_t1 = 0
    Energy_Usage_Production_t1 = 0
    Energy_Usage_t1 = 0
    AtmoEmissions_t1 = 0
    CO2_Level_t1 = AtmoEmissions_t1 + (CO2_Equilibrium_Fraction_Atm * (CO2_Level_t0 - CO2_Equilibrium)) + _
                    ((1 - CO2_Equilibrium_Fraction_Atm) * (1 - CO2_TransferRate_to_Atm) * (CO2_Level_t0 - CO2_Equilibrium)) + CO2_Equilibrium
    CO2_Transient_t1 = (1 - CO2_Equilibrium_Fraction_Atm) * AtmoEmissions_t1 + (1 - CO2_Equilibrium_Fraction_Atm) * _
                       (1 - CO2_TransferRate_to_Atm) * (CO2_Level_t0 - CO2_Equilibrium)
    New_CO2_Equilibrium_t1 = CO2_Level_t1 - CO2_Transient_t1
    Damages_Utility_t1 = 1
    Damages_CapitalStock_t1 = 1
    Damages_Production_t1 = 1
    Damages_Y_Composite_t1 = 1
    Damages_Composite_t1 = 1
    
    'If the economy is still living, then proceed through innerloop. Otherwise, go to outerloop.
    Else
            
'Begin Inner Loop xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Begin Inner Loop
'In the inner loop, an iteration process is used to solve for the damages, and production simultaneity problem. First solve the problem using the
'last periods damages, then calculate a new implied damage quantity. Then use the new computed damages to solve for production. Repeat the process until
'a solution converges.


    
    'Declare and set counter
    Dim w As Long
    
    w = 1
    
    'Declare and set conditional statement variable
    Dim Abs_Error As Double


    Abs_Error = 0.1




    Do Until Abs_Error < 0.005
    
        'Assume Damages are equal to their last computed values
        Damages_CapitalStock_t1 = Damages_CapitalStock_t0
        Damages_Utility_t1 = Damages_Utility_t0
        Damages_Production_t1 = Damages_Production_t0
        Damages_Composite_t1 = Damages_Composite_t0




        'Calculate Capital Stock. Remember, damages to capital stock acts like another depreciation rate.
        CapitalStock_t1 = Investment_t0 + (1 - Dep_k) ^ Period_Length * (1 - Damages_CapitalStock_t0) ^ Period_Length * CapitalStock_t0


        'Calculate Production function
        Output_t1 = GrowthFactor ^ (Period_Length) * (Output_t0 + FactorProductivity * (1 - Damages_Production_t1) * _
        (1 - AbatementCost_Production) * (CapitalStock_t1 - CapitalStock_t0) ^ Share_K_Capital * _
                    (Labor_t0 ^ Share_Labor))
        
        
        'Calculate World Accounting Equation: Consumption, Investment and Government Spending.


        Consumption_t1 = (Share_Consumption * Output_t1) * (1 - AbatementCost_Consumption) ^ (1 / (1 + MU_Elasticity))
        Investment_t1 = Share_Investment * Output_t1 + (1 - (1 - AbatementCost_Consumption) ^ (1 / (1 + MU_Elasticity)))
        Government_t1 = Share_Government * Output_t1
        TotalDeadWtLoss_t1 = Output_t1 - Consumption_t1 - Investment_t1 - Government_t1
    
    'Note: AtmoEmissions is the same as retained emissions.
    
        'Energy Balance
        Energy_Usage_Consumption_t1 = Energy_to_Consumption_Ratio * Consumption_t1
        Energy_Usage_Production_t1 = Energy_to_Production_Ratio * Output_t1
        Energy_Usage_t1 = Energy_Usage_Consumption_t1 + Energy_Usage_Production_t1
        AtmoEmissions_Consumption_t1 = Emissions_Consumption_Ratio * Consumption_t1
        AtmoEmissions_Output_t1 = Emissions_Output_Ratio * Output_t1
        AtmoEmissions_t1 = AtmoEmissions_Consumption_t1 + AtmoEmissions_Output_t1
        
        'CO2 Level
        CO2_Level_t1 = AtmoEmissions_t1 + (CO2_Equilibrium_Fraction_Atm * (CO2_Level_t0 - CO2_Equilibrium)) + _
                    ((1 - CO2_Equilibrium_Fraction_Atm) * (1 - CO2_TransferRate_to_Atm) * (CO2_Level_t0 - CO2_Equilibrium)) + CO2_Equilibrium
        CO2_Transient_t1 = (1 - CO2_Equilibrium_Fraction_Atm) * AtmoEmissions_t1 + (1 - CO2_Equilibrium_Fraction_Atm) * _
                       (1 - CO2_TransferRate_to_Atm) * (CO2_Level_t0 - CO2_Equilibrium)
        New_CO2_Equilibrium_t1 = CO2_Level_t1 - CO2_Transient_t1
        
        'New Temperature Deviation
        Dim Temp_Off_t1 As Double
        Temperature_Critical = Sheets(1).Range("K28")
    
        Forcing_t1 = 3.35 * (Log(1 + 1.2 * CO2_Level_t1 + 0.005 * CO2_Level_t1 ^ 2 + 1.4 * 10 ^ (-6) * CO2_Level_t1 ^ 3) _
                    - Log(1 + 1.2 * CO2_Equilibrium + 0.005 * CO2_Equilibrium ^ 2 + 1.4 * 10 ^ (-6) * CO2_Equilibrium ^ 3))
    
        Temp_Off_t1 = ClimateSensitivity_Lambda * Forcing_t1
        If Temp_Off_t1 < Temperature_Critical Then
                Switch = 0
                Else
                    Switch = 1
                    End If
                      
        Temp_t1 = Temp_Off_t1 + ClimateSensitivityParameter_b2 * Switch * (CO2_Level_t1 / CO2_Equilibrium)
    
        'Damages
        Damages_Utility_t1 = 1 - (1 / (1 + Proportional_Constant_Temperature_U * Temp_t1 + Exponent_Constant_Temperature_U * Temp_t1 ^ 2))
        Damages_Production_t1 = 1 - (1 / (1 + Proportional_Constant_Temperature_Y * Temp_t1 + Exponent_Constant_Temperature_Y * Temp_t1 ^ 2))
        Damages_CapitalStock_t1 = 1 - (1 / (1 + Proportional_Constant_Temperature_K * Temp_t1 + Exponent_Constant_Temperature_K * Temp_t1 ^ 2))
        Damages_Y_Composite_t1 = 1 - (1 - Damages_Production_t1) * (1 - Damages_CapitalStock_t1) ^ Share_K_Capital
        Damages_Composite_t1 = Damages_Utility_t1 + (1 - Damages_Utility_t1) * Damages_Utility_t1 * (Damages_Y_Composite_t1 ^ MU_Elasticity)
        
                   
        'Begin Error Calculations
        'Termination or continuance condition of iteration process. If error is small enough terminate loop. Termination also occurs
     'when 100 iteration attempts have been made.
     
        
        If w = 1 Then
            Abs_Error = 0.001
            End If
        
        If w > 1 And w < 100 Then
            Abs_Error = Abs((Output_t1 - Output_t0) / Output_t0)
                End If
                
    If Abs_Error > 0.005 Then
    
    'Reset t1 variables as t0 variables and start at the beginning of the loop.
        
        Damages_Utility_t0 = Damages_Utility_t1
        Damages_Production_t0 = Damages_Production_t1
        Damages_Y_Composite_t0 = Damages_Y_Composite_t0
        Damages_Composite_t0 = Damages_Composite_t1
        
     End If
        
        'Termination or continuance condition of iteration process. If error is small enough terminate loop. Termination also occurs
        'when 100 iteration attempts have been made.
     
     w = w + 1
    
      
    Loop
        'End Inner Loop xxxxxxxxxxxxxxxxxxxxx'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx End Inner Loop
    End If
        
        
   'Utility and welfare calculations
   
        'Survivability Probability
        Survivability_Function_t1 = 1 - (Temp_t1 ^ 2 / (Temp_Max ^ 2 + 1.96 * (Temp_Max - Temp_t1) ^ 2))
        
        If Survivability_Function_t1 <= 0 Then
            Temp_t1 = SKI_Limit_Temp
            Survivability_Function_t1 = 0
            End If
 
        'Utility Index
        Raw_Utility_Index_t1 = (Survivability_Function_t1 * (Consumption_t1 ^ MU_Elasticity)) / MU_Elasticity
        Utility_Index_t1 = Utility_Normalization_Factor * Raw_Utility_Index_t1
    
        'Welfare
        Welfare_t1 = Welfare_t0 + Discount_Factor ^ Period_Length * Utility_Index_t1
   
    
    'Print output
    Sheets(1).Range("P" & 3 + t, "AK" & 3 + t).Value = _
    Array(Output_t1, CapitalStock_t1, Consumption_t1, Investment_t1, Government_t1, TotalDeadWtLoss_t1, _
        Energy_Usage_Consumption_t1, Energy_Usage_Production_t1, Energy_Usage_t1, AtmoEmissions_t1, CO2_Level_t1, _
        CO2_Transient_t1, New_CO2_Equilibrium_t1, Temp_t1, Damages_Utility_t1, Damages_CapitalStock_t1, Damages_Production_t1, _
        Damages_Y_Composite_t1, Damages_Composite_t1, Survivability_Function_t1, Utility_Index_t1, Welfare_t1)
        
        
        
     'Reset stock variables and survivability function
     Damages_CapitalStock_t0 = Damages_CapitalStock_t1
     Investment_t0 = Investment_t1
     CapitalStock_t0 = CapitalStock_t1
     Output_t0 = Output_t1
     CO2_Level_t0 = CO2_Level_t1
     Welfare_t0 = Welfare_t1
     Survivability_Function_t0 = Survivability_Function_t1
        
    t = t + 1
        
Loop
    
    
'End of outer loop VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV End of Outer Loop


End Sub
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Sub Routines to Main Program Below XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


Sub Initial_EconVariable(Output_t0 As Double, Share_Consumption As Double, Share_Investment As Double, Share_Government As Double, _
    Consumption_t0 As Double, Investment_t0 As Double, Government_t0 As Double)


    'Set value to initial variables
        Output_t0 = Sheets(1).Range("K40")
        Share_Consumption = Sheets(1).Range("K50")
        Share_Investment = Sheets(1).Range("K51")
        Share_Government = Sheets(1).Range("K52")
  
    'Calculate initial consumption, investment and government spending.
        Consumption_t0 = Share_Consumption * Output_t0
        Investment_t0 = Share_Investment * Output_t0
        Government_t0 = Output_t0 - Consumption_t0 - Investment_t0
    
End Sub




Sub Initial_Emissions(Retained_Emissions As Double, CO2_Level_t0 As Double, CO2_Equilibrium As Double, _
                            CO2_Equilibrium_Fraction_Atm As Double, CO2_TransferRate_to_Atm As Double, Retention_Rate, Total_Emissions)


    'We have data on the net emissions of CO2 into the atmosphere, but not the actual gross quantity. This subroutine calculates the gross quantity
    'of CO2 emsissions into the atmosphere.


        CO2_Level_t0 = Sheets(1).Range("K55")
        CO2_Equilibrium = Sheets(1).Range("K54")
        CO2_Equilibrium_Fraction_Atm = Sheets(1).Range("K19")
        CO2_TransferRate_to_Atm = Sheets(1).Range("K21")
        Retention_Rate = Sheets(1).Range("K17")
    
        Retained_Emissions = (1 - CO2_Equilibrium_Fraction_Atm) * CO2_TransferRate_to_Atm * (CO2_Level_t0 - 2.11 - CO2_Equilibrium) + 2.11
        Total_Emissions = Retained_Emissions / Retention_Rate


End Sub




Sub EnergyUsage(Energy_Usage_Total As Double, Energy_Usage_Consumption As Double, Energy_Usage_Production As Double)
                'Energy_to_Consumption_Ratio As Double, Energy_to_Production_Ratio As Double)
                
      'Declare Total_Emissions as local variable
        Dim Total_Emissions As Double
        Dim Consumption_t0 As Double
        Dim Output_t0 As Double
        
        Total_Emissions = Sheets(1).Range("K60")
        Consumption_t0 = Sheets(1).Range("K47")
        Output_t0 = Sheets(1).Range("K40")


    'There is 3.539 ppmv of CO2 emitted for every 1 TW-Yr of energy usage. Also convert to GWatt-hrs by multiplying by 1000
        Energy_Usage_Total = (Total_Emissions / 3.539) * 1000
        Sheets(1).Cells(62, 11) = Energy_Usage_Total
    
    'I estimate that 40% emissions come from consumption and 60% come from production.
        Energy_Usage_Consumption = 0.4 * Energy_Usage_Total
        Energy_Usage_Production = 0.6 * Energy_Usage_Total
    
    
        
End Sub




Sub Energy_Mass_Ratios(Energy_to_Consumption_Ratio As Double, Energy_to_Production_Ratio As Double, EC_to_EY_Ratio As Double, _
                        Emissions_Consumption_Ratio, Emissions_Output_Ratio)




    'Declare local variables
    Dim Consumption_t0 As Double
    Dim Output_t0 As Double
    Dim Energy_Usage_Consumption As Double
    Dim Energy_Usage_Production As Double
    Dim Share_Consumption As Double
    Dim Retained_Emissions As Double
    
    
    Consumption_t0 = Sheets(1).Range("K47")
    Output_t0 = Sheets(1).Range("K40")
    Energy_Usage_Consumption = Sheets(1).Range("K63")
    Energy_Usage_Production = Sheets(1).Range("K64")
    Share_Consumption = Sheets(1).Range("K50")
    Retained_Emissions = Sheets(1).Range("K59")
    
    
    'Energy to consumption and production ratios
    Energy_to_Consumption_Ratio = Energy_Usage_Consumption / Consumption_t0
    Energy_to_Production_Ratio = Energy_Usage_Production / Output_t0


    'Calculate the EC/EY ratio. In the initial period, according to the data .62Y = C.
    EC_to_EY_Ratio = Share_Consumption * (Energy_to_Consumption_Ratio / Energy_to_Production_Ratio)
    
    'Atmospheric CO2 emissions to consumption and production ratios. Also denoted as gamma(c) and gamma(y) in this research.
    Emissions_Consumption_Ratio = 0.4 * Retained_Emissions / Consumption_t0
    Emissions_Output_Ratio = 0.6 * Retained_Emissions / Output_t0


End Sub




Sub Forcing(Forcing_t0 As Double)


    'Declare and set local Variables
    Dim CO2_Level_t0 As Double
    Dim CO2_Equilibrium As Double
    
    CO2_Level_t0 = Sheets(1).Range("K55")
    CO2_Equilibrium = Sheets(1).Range("K54")
    
    'Calculate Initial Forcing
    Forcing_t0 = 3.35 * (Log(1 + 1.2 * CO2_Level_t0 + 0.005 * CO2_Level_t0 ^ 2 + 1.4 * 10 ^ (-6) * CO2_Level_t0 ^ 3) _
                      - Log(1 + 1.2 * CO2_Equilibrium + 0.005 * CO2_Equilibrium ^ 2 + 1.4 * 10 ^ (-6) * CO2_Equilibrium ^ 3))


End Sub


Sub NewEquilibrium(New_CO2_Equilibrium_t0 As Double)


    'Declare and set local variables
    Dim C02_Level_t0 As Double
    Dim CO2_Equilibrium As Double
    Dim CO2_Equilibrium_Fraction_Atm
    
    C02_Level_t0 = Sheets(1).Range("K55")
    CO2_Equilibrium = Sheets(1).Range("K54")
    CO2_Equilibrium_Fraction_Atm = Sheets(1).Range("K19")


    'Calculate new long run CO2 equilibrium concentration level
    New_CO2_Equilibrium_t0 = CO2_Equilibrium_Fraction_Atm * (C02_Level_t0 - CO2_Equilibrium) + CO2_Equilibrium




End Sub


Sub Temperature(ClimateSensitivity_Lambda As Double, ClimateSensitivityParameter_b1 As Double, _
                         Lambda As Double, Temperature_Critical_Max As Double, _
                         CO2_SKI As Double, SKI_Limit_Temp As Double, ClimateSensitivityParameter_b2 As Double, Temp_t0 As Double)


    'Declare and set local variables
    Dim ClimateSensitivity
    Dim CO2_Level_t0 As Double
    Dim CO2_Equilibrium As Double
    Dim CO2_Ratio_Critical As Double
    Dim Forcing_t0 As Double
    
    ClimateSensitivity = Sheets(1).Range("K24")
    CO2_Level_t0 = Sheets(1).Range("K55")
    CO2_Equilibrium = Sheets(1).Range("K54")
    Temperature_Critical_Max = Sheets(1).Range("K29")
    Forcing_t0 = Sheets(1).Range("K57")
    
    'Calculate Proportionality Constant
    ClimateSensitivity_Lambda = ClimateSensitivity / (3.35 * (Log(1 + 1.2 * (2 * CO2_Level_t0) + 0.005 * (2 * CO2_Level_t0) ^ 2 + 1.4 * 10 ^ (-6) * _
                                (2 * CO2_Level_t0) ^ 3) - Log(1 + 1.2 * CO2_Equilibrium + 0.005 * CO2_Equilibrium ^ 2 + 1.4 * 10 ^ (-6) * _
                                CO2_Equilibrium ^ 3)))
                                
        
    'Calculate Climate Sensitivity Parameter b1
    ClimateSensitivityParameter_b1 = ClimateSensitivity * ClimateSensitivity_Lambda
    
    
    'Approximation of SKI concentration ratio and concentration
     Lambda = ClimateSensitivity / (5.35 * Log(2))
     CO2_Ratio_Critical = Exp(Temperature_Critical_Max / (Lambda * 5.35))
     Sheets(1).Cells(81, 11) = CO2_Ratio_Critical
     
     CO2_SKI = CO2_Equilibrium * CO2_Ratio_Critical
        
    'Calculate Climate Sensitivity Parameter b2
        'Note some simplifications were done to calculate this parameter. To calculate the concentration where the critical temperature was reached,
        'I assumed that the first order approximation of radioactive forcing was valid. Thus, forcing is proportional to the natural logs of new steady
        'state temperature and equilibrium temperature.
    
        'ClimateSensitivityParameter_b2 approximation
        SKI_Limit_Temp = Sheets(1).Range("K30")
        ClimateSensitivityParameter_b2 = (SKI_Limit_Temp - 5.35 * Lambda * Log(CO2_Ratio_Critical)) / (CO2_Ratio_Critical)
     
    'Calculate initial damages


        Temp_t0 = ClimateSensitivity_Lambda * Forcing_t0
        


End Sub






Sub Damages(Proportional_Constant_Temperature_U As Double, Exponent_Constant_Temperature_U As Double, Damages_Utility_t0 As Double, _
            Proportional_Constant_Temperature_Y As Double, Exponent_Constant_Temperature_Y As Double, Damages_Production_t0 As Double, _
            Proportional_Constant_Temperature_K As Double, Exponent_Constant_Temperature_K As Double, Damages_CapitalStock_t0 As Double, _
            Damages_Y_Composite_t0 As Double, Damages_Composite_t0 As Double)


    'Declare and set local variables
    Dim Temp_t0 As Double
    Dim Share_K_Capital As Double
    Dim MU_Elasticity As Double
    
    Temp_t0 = Sheets(1).Range("K58")
    Share_K_Capital = Sheets(1).Range("K8")
    MU_Elasticity = Sheets(1).Range("K7")


    'Utility Damages
    Proportional_Constant_Temperature_U = Sheets(1).Range("K36")
    Exponent_Constant_Temperature_U = Sheets(1).Range("K37")
    Damages_Utility_t0 = 1 - (1 / (1 + Proportional_Constant_Temperature_U * Temp_t0 + Exponent_Constant_Temperature_U * Temp_t0 ^ 2))
     
    'Production Damages
    Proportional_Constant_Temperature_Y = Sheets(1).Range("K32")
    Exponent_Constant_Temperature_Y = Sheets(1).Range("K33")
    Damages_Production_t0 = 1 - (1 / (1 + Proportional_Constant_Temperature_Y * Temp_t0 + Exponent_Constant_Temperature_Y * Temp_t0 ^ 2))
   
   'Capital Stock Damages
    Proportional_Constant_Temperature_K = Sheets(1).Range("K34")
    Exponent_Constant_Temperature_K = Sheets(1).Range("K35")
    Damages_CapitalStock_t0 = 1 - (1 / (1 + Proportional_Constant_Temperature_K * Temp_t0 + Exponent_Constant_Temperature_K * Temp_t0 ^ 2))
    
    'Composite Damages
    Damages_Y_Composite_t0 = 1 - (1 - Damages_Production_t0) * (1 - Damages_CapitalStock_t0) ^ Share_K_Capital
    Damages_Composite_t0 = Damages_Utility_t0 + (1 - Damages_Utility_t0) * Damages_Utility_t0 * (Damages_Y_Composite_t0 ^ MU_Elasticity)




End Sub


Sub AbatementCosts(AbatementCost_Production As Double, AbatementCost_Consumption As Double, DeadWtLoss_C As Double)


    'Declare and set local variables
    
    Dim Proportional_Production_Control As Double
    Dim Exponent_Production_Control As Double
    Dim Proportional_Consumption_Control As Double
    Dim Exponent_Consumption_Control As Double
    Dim ReductionRate_Production As Double
    Dim ReductionRate_Consumption As Double
    Dim Share_Consumption As Double
    
    Proportional_Consumption_Control = Sheets(1).Range("K12")
    Exponent_Consumption_Control = Sheets(1).Range("K13")
    Proportional_Production_Control = Sheets(1).Range("K14")
    Exponent_Production_Control = Sheets(1).Range("K15")
    ReductionRate_Production = Sheets(1).Range("K77")
    ReductionRate_Consumption = Sheets(1).Range("K78")
    Share_Consumption = Sheets(1).Range("K50")
    
    
    'Calculate Abatement Costs
    AbatementCost_Production = Proportional_Production_Control * ReductionRate_Production ^ Exponent_Production_Control
    AbatementCost_Consumption = Proportional_Consumption_Control * ReductionRate_Consumption ^ Exponent_Consumption_Control
    
    'Calculate Deadweight Loss
     DeadWtLoss_C = Share_Consumption * AbatementCost_Consumption


End Sub


Sub Survivability(Survivability_Function_t0 As Double)


    'Declare and set local variables
    Dim Temp_Max As Double
    Dim Temp_t0 As Double
    
    Temp_Max = Sheets(1).Range("K80")
    Temp_t0 = Sheets(1).Range("K58")
    
    Survivability_Function_t0 = 1 - (Temp_t0 ^ 2 / (Temp_Max ^ 2 + 1.96 * (Temp_Max - Temp_t0) ^ 2))
    




End Sub


Sub Initial_CapitalStock(CapitalStock_t0 As Double)


    'Calculate Initial Capital Stock. This is very controversial and is a reason why there is skepticsm of the Neo-Classical Model.
    'Nevertheless, we use Nordhaus estimate of 97.3 trillion dollars as the approximate world capital stock using purchasing power
    'parity (PPP) and in 2005 dollars. However, I use the exchange rate value and 2014 dollars. Thus, we must convert the units by multiplying
    'Nordhaus value by the ratio of world GDP exhange rate to GDP PPP multiplying the ratio of GDP in 2014 dollars to GDP in 2005 dollars.


        CapitalStock_t0 = 97.3 * (78.22 / 107.5) * (78.22 / 55.34)
        


End Sub


Sub Initial_Labor(Labor_t0 As Double)


    'Declare and set local variables.
    Dim Output_t0 As Double
    Dim AbatementCost_Production As Double
    Dim Damages_Production_t0 As Double
    Dim FactorProductivity As Double
    Dim CapitalStock_t0 As Double
    Dim Share_K_Capital As Double
    Dim Share_Labor As Double
    
    Output_t0 = Sheets(1).Range("K40")
    AbatementCost_Production = 0
    Damages_Production_t0 = Sheets(1).Range("K71")
    FactorProductivity = Sheets(1).Range("K45")
    CapitalStock_t0 = Sheets(1).Range("K41")
    Share_K_Capital = Sheets(1).Range("K8")
    Share_Labor = Sheets(1).Range("K9")
    
    
    
        'Calculate initial steady state labor supply. Abatement Costs are assumed to be zero.
        Labor_t0 = (Output_t0 / ((1 - AbatementCost_Production) * (1 - Damages_Production_t0) _
        * FactorProductivity * CapitalStock_t0 ^ Share_K_Capital)) ^ (1 / Share_Labor)


End Sub


Sub UtilityIndex(Utility_Index_t0 As Double, Welfare_t0 As Double, Utility_Normalization_Factor As Double)


    'Declare and set local variables.
    Dim Raw_Utility_Index_t0 As Double
    Dim Survivability_Function_t0 As Double
    Dim Consumption_t0 As Double
    Dim MU_Elasticity As Double
    
    Survivability_Function_t0 = Sheets(1).Range("K75")
    Consumption_t0 = Sheets(1).Range("K47")
    MU_Elasticity = Sheets(1).Range("K7")
    
    
    'Compute Variables
    Raw_Utility_Index_t0 = (Survivability_Function_t0 * (Consumption_t0 ^ MU_Elasticity)) / MU_Elasticity
    Utility_Normalization_Factor = 100 / Raw_Utility_Index_t0
    Utility_Index_t0 = Utility_Normalization_Factor * Raw_Utility_Index_t0
    Welfare_t0 = Utility_Index_t0


End Sub
 
Last edited by a moderator:
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top