Procedure for the cluster-robust Hausman test

The Hausman test cannot be run on robust std. errors we have separately make the FE and RE standard errors robust to serial correlation and heteroskedasticity by clustered standard errors. So, is there a specific procedure for the cluster-robust Hausman test?

My guess is:

1. Run FE

2. Run RE

3. Get residuals

4. Apply clustering analysis

5. Do the Hausman Test with cluster-robust std. errors

Let $x$ include all time-varying variables. You need to compute the random effects differences for the dependent $y_{it} - \widehat{\theta}\overline{y}_i$ and explanatory variables, $x_{it} - \widehat{\theta}\overline{x}_i$, as well as the within transformed explanatory variables $x_{it} - \overline{x}_i$. Then you can estimate the OLS regression
$$y_{it} - \widehat{\theta}\overline{y}_i = (1-\widehat{\theta})\alpha + (x_{it} - \widehat{\theta}\overline{x}_i)'\beta + (x_{it} - \overline{x}_i)'\gamma + \epsilon_{it}$$
The robust Hausman test amounts to a Wald test for $H_0:\gamma =0$. This is asymptotically equivalent to the standard test if random effects without clustered errors is already efficient.
In terms of programming this is easy if you have a balanced panel. If not, then this complicates things in the sense that you need to estimate $\widehat{\theta}_i$ for every panel unit. If you are interested in the Stata code you can have a look at Cameron and Trivedi (2009) "Microeconometrics Using Stata".