Hi,
I am struggling to compute leverage for the cases in -xtreg, re-
-xtreg, re- uses GLS estimator, and the projection matrix for GLS, after researching on a very prestigious econometrics handbook, (no, sorry, Wikipedia), is:

where Sigma is the covariance matrix of the errors
Two questions:
1: Where (how) do I get such Sigma matrix in Stata?
2: How can I create a matrix from factor variables?
After computing H, leverage (h) would be:
See an example code here:
I am struggling to compute leverage for the cases in -xtreg, re-
-xtreg, re- uses GLS estimator, and the projection matrix for GLS, after researching on a very prestigious econometrics handbook, (no, sorry, Wikipedia), is:
where Sigma is the covariance matrix of the errors
Two questions:
1: Where (how) do I get such Sigma matrix in Stata?
2: How can I create a matrix from factor variables?
After computing H, leverage (h) would be:
Code:
matrix h = vecdiag(H)'
Code:
. use "https://www.stata-press.com/data/r16/nlswork.dta" (National Longitudinal Survey. Young Women 14-26 years of age in 1968) . xtreg ln_wage age i.race ... . mkmat age i.race, mat(X) factor-variable and time-series operators not allowed r(101); .