Announcement

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

  • Calculate marginal effects in three-stage bootstrapped model

    Dear all,

    I am estimating a probit fixed-effects model with instrumental variables in three stages. The dependent variable is a dummy. The key independent variable is continuous and measured on an ordinal scale. In the first stage I transform it to an interval-scaled measure to reduce measurement error. I do this using a second order polynomial probit regression. Then, I use an instrumental variable to address within-group endogeneity based on a control function approach i.e. I run a linear regression in the second stage and use the estimates of the second stage error terms as control variables in the third stage probit regression. For the fixed effects, I use the Mundlak's approach (I control for the covariate's mean in the regression).

    Since I am using predicted scores I wrote a little programme to bootstrap the standard errors in all the three stages. The code works but I can't figure out how to calculate the marginal effects for the probit model in the third stage. Any help would be beyond appreciated.


    Here is my code so far:

    Code:
    program "threestage", eclass
    
    *First stage: Anchoring
    probit levl2em ks3 ks3q
    tempname prlevl2em
    predict double `prlevl2em', pr  
    
    tempname logprlevl2em mean_logprlevl2em xb residual
    
    g `logprlevl2em'=ln(logprlevl2em) // log transformation
    bysort pid: egen `mean_logprlevl2em'=mean(mean_logprlevl2em) //mean for fixed effects
    
    *Main model
    
    /***Control function approach: use the estimates of the first stage error terms
    as control variables in the second stage ***/
    
    *Second stage: linear regression
    reg `logprlevl2em' lognpks3 mean_lognpks3 s2 s3
    predict `xb' if e(sample), xb
    g `residual' = `logprl2em' - `xb' if e(sample)
    
    *Third stage: probit
    probit y `logprlevl2em' `residual' `mean_logprlevl2em' mean_lognpks3 s2 s3
    
    tempvar used
    gen byte `used' = e(sample)
    
    tempname b
    mat `b' = e(b)
    mat colnames `b' = logprlevl2em residual mean_logprlevl2em mean_lognpks3 s2 s3 _cons
    
    ereturn post `b', esample(`used')
    
    end
    
    set seed 49557687
    bootstrap "threestage" _b, reps(1000) cluster(pid)
    The command I want to use for the marginal effects is:

    Code:
    margins, dydx(logprlevl2em s2 s3) post predict(pr)

  • #2
    Hi everyone,

    To add to my previous post, I wanted to share that the solution was as simple as replacing "tempname" with "tempvar". The code now runs smoothly.

    Hope this will help someone else in the future.

    Konstantina

    Comment

    Working...
    X