Example #1
0
def calculateStandardErrorsByBootstrap(initial_estimate,
                                       N,
                                       seed=0,
                                       verbose=False):
    '''
    Estimates the SolvingMicroDSOPs model N times, then calculates standard errors.
    '''

    t_0 = time()

    # Generate a list of seeds for generating bootstrap samples
    RNG = np.random.RandomState(seed)
    seed_list = RNG.randint(2**31 - 1, size=N)

    # Estimate the model N times, recording each set of estimated parameters
    estimate_list = []
    for n in range(N):
        t_start = time()

        # Bootstrap a new dataset by sampling
        bootstrap_data = (bootstrapSampleFromData(Data.scf_data_array,
                                                  seed=seed_list[n])).T
        w_to_y_data_bootstrap = bootstrap_data[0, ]
        empirical_groups_bootstrap = bootstrap_data[1, ]
        empirical_weights_bootstrap = bootstrap_data[2, ]

        # Make a temporary function for use in this estimation run
        smmObjectiveFxnBootstrap = lambda parameters_to_estimate: smmObjectiveFxn(
            DiscFacAdj=parameters_to_estimate[0],
            CRRA=parameters_to_estimate[1],
            empirical_data=w_to_y_data_bootstrap,
            empirical_weights=empirical_weights_bootstrap,
            empirical_groups=empirical_groups_bootstrap)

        # Estimate the model with the bootstrap data and add to list of estimates
        this_estimate = minimizeNelderMead(smmObjectiveFxnBootstrap,
                                           initial_estimate)
        estimate_list.append(this_estimate)
        t_now = time()

        # Report progress of the bootstrap
        if verbose:
            print('Finished bootstrap estimation #' + str(n + 1) + ' of ' +
                  str(N) + ' in ' + str(t_now - t_start) + ' seconds (' +
                  str(t_now - t_0) + ' cumulative)')

    # Calculate the standard errors for each parameter
    estimate_array = (np.array(estimate_list)).T
    DiscFacAdj_std_error = np.std(estimate_array[0])
    CRRA_std_error = np.std(estimate_array[1])

    return [DiscFacAdj_std_error, CRRA_std_error]
Example #2
0
def calculateStandardErrorsByBootstrap(initial_estimate,N,seed=0,verbose=False):
    '''
    Estimates the SolvingMicroDSOPs model N times, then calculates standard errors.
    '''
    
    t_0 = time()    
    
    # Generate a list of seeds for generating bootstrap samples
    RNG = np.random.RandomState(seed)
    seed_list = RNG.randint(2**31-1,size=N)    
    
    # Estimate the model N times, recording each set of estimated parameters
    estimate_list = []
    for n in range(N):
        t_start = time()
        
        # Bootstrap a new dataset by sampling 
        bootstrap_data = (bootstrapSampleFromData(Data.scf_data_array,seed=seed_list[n])).T
        w_to_y_data_bootstrap = bootstrap_data[0,]
        empirical_groups_bootstrap = bootstrap_data[1,]
        empirical_weights_bootstrap = bootstrap_data[2,]
        
        # Make a temporary function for use in this estimation run
        smmObjectiveFxnBootstrap = lambda parameters_to_estimate : smmObjectiveFxn(DiscFacAdj=parameters_to_estimate[0],
                                                                                   CRRA=parameters_to_estimate[1],
                                                                                   empirical_data = w_to_y_data_bootstrap,
                                                                                   empirical_weights = empirical_weights_bootstrap,
                                                                                   empirical_groups = empirical_groups_bootstrap)
                                                                                   
        # Estimate the model with the bootstrap data and add to list of estimates
        this_estimate = minimizeNelderMead(smmObjectiveFxnBootstrap,initial_estimate)
        estimate_list.append(this_estimate)
        t_now = time()  
        
        # Report progress of the bootstrap
        if verbose:
            print('Finished bootstrap estimation #' + str(n+1) + ' of ' + str(N) + ' in ' + str(t_now-t_start) + ' seconds (' + str(t_now-t_0) + ' cumulative)')
        
    # Calculate the standard errors for each parameter
    estimate_array = (np.array(estimate_list)).T
    DiscFacAdj_std_error = np.std(estimate_array[0])
    CRRA_std_error = np.std(estimate_array[1])
    
    return [DiscFacAdj_std_error, CRRA_std_error]
Example #3
0
 standard_errors : [float,float]
     Standard errors calculated by bootstrap: [DiscFacAdj_std_error, CRRA_std_error].
 '''    
 t_0 = time()    
 
 # Generate a list of seeds for generating bootstrap samples
 RNG = np.random.RandomState(seed)
 seed_list = RNG.randint(2**31-1,size=N)    
 
 # Estimate the model N times, recording each set of estimated parameters
 estimate_list = []
 for n in range(N):
     t_start = time()
     
     # Bootstrap a new dataset by resampling from the original data
     bootstrap_data = (bootstrapSampleFromData(Data.scf_data_array,seed=seed_list[n])).T
     w_to_y_data_bootstrap = bootstrap_data[0,]
     empirical_groups_bootstrap = bootstrap_data[1,]
     empirical_weights_bootstrap = bootstrap_data[2,]
     
     # Make a temporary function for use in this estimation run
     smmObjectiveFxnBootstrap = lambda parameters_to_estimate : smmObjectiveFxn(DiscFacAdj=parameters_to_estimate[0],
                                                                                CRRA=parameters_to_estimate[1],
                                                                                empirical_data = w_to_y_data_bootstrap,
                                                                                empirical_weights = empirical_weights_bootstrap,
                                                                                empirical_groups = empirical_groups_bootstrap)
                                                                                
     # Estimate the model with the bootstrap data and add to list of estimates
     this_estimate = minimizeNelderMead(smmObjectiveFxnBootstrap,initial_estimate)
     estimate_list.append(this_estimate)
     t_now = time()  
Example #4
0
def calculateStandardErrorsByBootstrap(initial_estimate,N,seed=0,verbose=False):
    '''
    Calculates standard errors by repeatedly re-estimating the model with datasets
    resampled from the actual data.
   
    Parameters
    ----------
    initial_estimate : [float,float]
        The estimated [DiscFacAdj,CRRA], for use as an initial guess for each
        re-estimation in the bootstrap procedure.
    N : int
        Number of times to resample data and re-estimate the model.
    seed : int
        Seed for the random number generator.
    verbose : boolean
        Indicator for whether extra output should be printed for the user.
        
    Returns
    -------
    standard_errors : [float,float]
        Standard errors calculated by bootstrap: [DiscFacAdj_std_error, CRRA_std_error].
    '''    
    t_0 = time()    
    
    # Generate a list of seeds for generating bootstrap samples
    RNG = np.random.RandomState(seed)
    seed_list = RNG.randint(2**31-1,size=N)    
    
    # Estimate the model N times, recording each set of estimated parameters
    estimate_list = []
    for n in range(N):
        t_start = time()
        
        # Bootstrap a new dataset by resampling from the original data
        bootstrap_data = (bootstrapSampleFromData(Data.scf_data_array,seed=seed_list[n])).T
        w_to_y_data_bootstrap = bootstrap_data[0,]
        empirical_groups_bootstrap = bootstrap_data[1,]
        empirical_weights_bootstrap = bootstrap_data[2,]
        
        # Make a temporary function for use in this estimation run
        smmObjectiveFxnBootstrap = lambda parameters_to_estimate : smmObjectiveFxn(DiscFacAdj=parameters_to_estimate[0],
                                                                                   CRRA=parameters_to_estimate[1],
                                                                                   empirical_data = w_to_y_data_bootstrap,
                                                                                   empirical_weights = empirical_weights_bootstrap,
                                                                                   empirical_groups = empirical_groups_bootstrap)
                                                                                   
        # Estimate the model with the bootstrap data and add to list of estimates
        this_estimate = minimizeNelderMead(smmObjectiveFxnBootstrap,initial_estimate)
        estimate_list.append(this_estimate)
        t_now = time()  
        
        # Report progress of the bootstrap
        if verbose:
            print('Finished bootstrap estimation #' + str(n+1) + ' of ' + str(N) + ' in ' + str(t_now-t_start) + ' seconds (' + str(t_now-t_0) + ' cumulative)')
        
    # Calculate the standard errors for each parameter
    estimate_array = (np.array(estimate_list)).T
    DiscFacAdj_std_error = np.std(estimate_array[0])
    CRRA_std_error = np.std(estimate_array[1])
    
    return [DiscFacAdj_std_error, CRRA_std_error]
Example #5
0
def calculateStandardErrorsByBootstrap(initial_estimate,
                                       N,
                                       seed=0,
                                       verbose=False):
    '''
    Calculates standard errors by repeatedly re-estimating the model with datasets
    resampled from the actual data.
   
    Parameters
    ----------
    initial_estimate : [float,float]
        The estimated [DiscFacAdj,CRRA], for use as an initial guess for each
        re-estimation in the bootstrap procedure.
    N : int
        Number of times to resample data and re-estimate the model.
    seed : int
        Seed for the random number generator.
    verbose : boolean
        Indicator for whether extra output should be printed for the user.
        
    Returns
    -------
    standard_errors : [float,float]
        Standard errors calculated by bootstrap: [DiscFacAdj_std_error, CRRA_std_error].
    '''
    t_0 = time()

    # Generate a list of seeds for generating bootstrap samples
    RNG = np.random.RandomState(seed)
    seed_list = RNG.randint(2**31 - 1, size=N)

    # Estimate the model N times, recording each set of estimated parameters
    estimate_list = []
    for n in range(N):
        t_start = time()

        # Bootstrap a new dataset by resampling from the original data
        bootstrap_data = (bootstrapSampleFromData(Data.scf_data_array,
                                                  seed=seed_list[n])).T
        w_to_y_data_bootstrap = bootstrap_data[0, ]
        empirical_groups_bootstrap = bootstrap_data[1, ]
        empirical_weights_bootstrap = bootstrap_data[2, ]

        # Make a temporary function for use in this estimation run
        smmObjectiveFxnBootstrap = lambda parameters_to_estimate: smmObjectiveFxn(
            DiscFacAdj=parameters_to_estimate[0],
            CRRA=parameters_to_estimate[1],
            empirical_data=w_to_y_data_bootstrap,
            empirical_weights=empirical_weights_bootstrap,
            empirical_groups=empirical_groups_bootstrap)

        # Estimate the model with the bootstrap data and add to list of estimates
        this_estimate = minimizeNelderMead(smmObjectiveFxnBootstrap,
                                           initial_estimate)
        estimate_list.append(this_estimate)
        t_now = time()

        # Report progress of the bootstrap
        if verbose:
            print('Finished bootstrap estimation #' + str(n + 1) + ' of ' +
                  str(N) + ' in ' + str(t_now - t_start) + ' seconds (' +
                  str(t_now - t_0) + ' cumulative)')

    # Calculate the standard errors for each parameter
    estimate_array = (np.array(estimate_list)).T
    DiscFacAdj_std_error = np.std(estimate_array[0])
    CRRA_std_error = np.std(estimate_array[1])

    return [DiscFacAdj_std_error, CRRA_std_error]