Dear Forum members,

Let me apologize in advance if my question has been dealt with somewhere which I have not found yet. I have searched the web and statalist severally, including posting this same question under an old thread. But I have not received any comment or help. As such I thought I should start a fresh thread altogether with an improved version of the question. My question is as follows:

I am dealing with a panel data with about 1400 panels over 5 year period. I wanted to do a quantile regression with fixed effects. I have learnt Joao Santos Silva and others that quantile regressions for panel data models with fixed effects is an area that is still being explored(developed) by the experts. My supervisor asked that I use Canay's (2011) Fixed-Effect Quantile Panel Data Approach.

Unfortunately, I have two endogenous variables(x1 and x2) among my list of independent variables. I have two instruments for each of them (z1 and z2). So I thought of using the standard 2SLS approach to manually collect the predicted values of my endogenous variables in the first stage and then in the second stage I implement Canay's approach, replacing x1 and x2 with x1_hat and x2_hat (the predicted values).

To ensure the the second step of Canay's 2step takes into account both the first step and the first stage of the 2SLS estimations, I sought to bootstrap all the stages/steps so as to avoid or reduce the incidence of biased standard-errors.

However, the bootsrap produces the error :
Code:
insufficient observations to compute bootstrap standard errors
no results will be saved
r(2000);
I produce the entire code/program below. But before that, I wanted to find out if thought process is correct given what I wanted to achieve. And I would appreciate it if I can get help to resolve the error I am getting.

Thank you in advance.

Below is the program:

Code:
 log using "Caney_2step"
 
cap program drop Caney2step
program define Caney2step

   xtset ind year

   xtreg  x1 z1 z2 x3 x4 x5 x6 i.year i.x7, fe vce(robust)
   predict x1_hat

   xtreg x2 z1 z2 x3 x4 x5 x6 i.year i.x7, fe vce(robust)
   predict x2_hat

   tsset ind year

   local qs "0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95"

//*now Canay's 2-step estimator*
//*Step 1*
//*Should i.year and i.x7 still be included here? I dont't think so. Thus I exclude them*

    xtreg y x1_hat x2_hat x3 x4 x5 x6, fe vce(robust)

    predict res, u  

    gen y_transormed = y - res

//*Step 2*
local replace replace  
 *forvalues tau = 0.05(0.05)0.95 {
 foreach tau in `qs' {
   qreg y_transormed x1_hat x2_hat x3 x4, quantile(`tau')  
   outreg2 using "Caney_2step", excel dec(4) ctitle(`tau') `replace'
   local replace append
 }
  
end

//*bootstrap the standard errors*
bootstrap, reps(200) nodrop: Caney2step
PS: code for implementing Caney's two-steps is as per suggestion by @River Huang

Below is my output:

Code:
 cap program drop Caney2step

.
. program define Caney2step
  1.
.
.
.    xtset ind year
  2.
.
.
.    xtreg  x1 z1 z2 x3 x4 x5 x6 i.year i.x7, fe vce(robust)
  3.
.    predict x1_hat
  4.
.
.
.    xtreg x2 z1 z2 x3 x4 x5 x6 i.year i.x7, fe vce(robust)
  5.
.    predict x2_hat
  6.
.
.
.    tsset ind year
  7.
.
.
.    local qs "0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95"
  8.
.
.
. *now Canay's 2-step estimator*
.
. *Step 1*
.
. *Should i.year and i.x7 still be included here? I dont't think so. Thus I exclude them*
.
.
.
.     xtreg y x1_hat x2_hat x3 x4 x5 x6, fe vce(robust)
  9.
.
.
.     predict res, u  
 10.
.
.
.     gen y_transormed = y - res
 11.
.
.
. *Step 2*
.
. local replace replace  
 12.
.  *forvalues tau = 0.05(0.05)0.95 {
.
.  foreach tau in `qs' {
 13.
.    qreg y_transormed x1_hat x2_hat x3 x4, quantile(`tau')  
 14.
.    outreg2 using "Caney_2step", excel dec(4) ctitle(`tau') `replace'
 15.
.    local replace append
 16.
.  }
 17.
.    
.
. end

.
.
.
. *bootstrap the standard errors*

.
. bootstrap, reps(200) nodrop: Caney2step
(running Caney2step on estimation sample)
 :  :  :  :  :  :  :  :  :  :  :  :  :  :  :  :  :  :  :
Bootstrap replications (200)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    50
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx   100
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx   150
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx   200
insufficient observations to compute bootstrap standard errors
no results will be saved
r(2000);

Your kind suggestions will be appreciated.