Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Post-regression: Augmenting regression function with a random shock

    Hi,
    i'm trying to use fitted values, predicted standard errors and a random 'shock', drawn from the empirical distribution of residuals of the initial regression to create a Monte Carlo estimate of the future value of my dependent variable (which is change in consumption)

    ** preparing dependent variable
    sort ID year
    bysort ID: gen d_exp=(expenditure_deflated[_n]-expenditure_deflated[_n-1])/expenditure_deflated[_n-1] if year==year[_n-1]+1

    **regression with weights
    bootstrap, reps(1000): reg d_exp dependency education grants female hh_age rural white african wx_hhsizer [pw=wx_wgt], ro
    predict exp_u2, stdp
    predict fitted, xb
    estimates store reg3

    Now here's the part that i don't know.
    It's supposed to look like this: NEW_VAR=FITTED VALUES+RANDOM DRAW FROM RESIDUALS OF REGRESSION.
    The tricky part is the random draw. It's easy to use a uniform distribution, for example, and draw one number from it, but drawing one data point for each observation from existing data (a random 'shock'?! Any ideas? Thank you!


  • #2
    So, if I understand your question correctly, you want to draw random samples, with replacement, from the empirical distribution of residuals from your regression. I think this does it:

    Code:
    // RUN YOUR REGRESSION AS NOTED IN YOUR OWN POST #1
    // AND PREDICT FITTED VALUES
    
    // SAVE ORIGINAL DATA
    preserve
    
    // CALCULATE RESIDUALS & CREATE A DATA SET OF 
    tempfile residuals
    predict e, resid
    keep e
    save `residuals'
    
    // BRING BACK ORIGINAL DATA AND PREPARE TO START SIMULATION LOOP
    restore
    ... // PREPARE TO SIMULATE
    
    
    // WHAT FOLLOWS WILL BE  YOUR SIMULATION REPETITION LOOP
    forvalues i = 1/`n_reps' {
    
        ... // DO STUFF
    
        // AT THIS POINT YOU HAVE SOME DATA SET AND YOU WANT TO MERGE IN A RANDOM
        // SAMPLE OF RESIDUALS
        tempfile working_data
        save `working_data'
    
        // GET SIMPLE RANDOM SAMPLE WITH REPLACEMENT
        // AND MERGE TO WORKING DATA
        use `residuals', clear
        bsample
        merge 1:1 _n using `working_data'
        gen new_var = fitted + e
    
        // MORE CODE WITHIN YOUR SIMULATION
        ... // DO REMAINING STUFF
    
    }

    Comment

    Working...
    X