I have a question regarding weighing observations by importance.

Suppose I am running the following regression:$$log(y_{it}/y_{it-1})=\alpha+\sum_{i=1}^{N}\gamma_{i}Country_{i}+u_{i}$$ where basically my LHS is GDP growth of country $i$ at time $t$ that I regress on a full set of country dummies (-1).
I want to weigh the observations by the GDP of the country. If I am doing this on stata, what weights are appropriate? Frequency weights or probability weights? My intuition is that I have to basically run a weighted least squares regression of the form: $$ \hat{\beta}=(x'Wx)^{-1}(x'Wy)$$

where $W$ is a diagonal matrix with the weights (GDP) on the diagonal. I am at a loss regarding how to implement this on Stata. Thanks!

  • $\begingroup$ You should consider looking at the Generalized Least Squares (GLS) method, it's basically a 2 step OLS where you try to find the optimal weighting matrix at the 2nd step. $\endgroup$
    – Louis. B
    Nov 25, 2015 at 1:39
  • $\begingroup$ Not to take away from the economic forum, but if you ask the question about Stata programming on Stack Overflow, they will help you with the code much quicker. I must share that I don't use Stata, I prefer Matlab/Excel combo so my opinion is not very credible. $\endgroup$ Nov 25, 2015 at 5:40

1 Answer 1


If you check Stata's help file on regress you should understand how to do it. Particularly pp. 16-7 have specific examples of how to apply weights.

I will edit in order to be more detailed.

gen lnyl1y=ln(y)-l1.ln(y)
xi: reg lnyl1y i.country [w=y]

Notice that if the weighted regression is done by dividing all values for observation $i$ by $\sqrt{w_i}$, then $$\tilde{x} = \begin{pmatrix} \frac{x_{1,1}}{\sqrt{w_1}} & \cdots & \frac{x_{1,k}}{\sqrt{w_1}}\\ \vdots &\ddots &\vdots\\ \frac{x_{n,1}}{\sqrt{w_n}} & \cdots & \frac{x_{n,k}}{\sqrt{w_n}} \end{pmatrix} $$ Call the diagonal matrix composed of $\sqrt{w_i}$ in the $(i,i)$ element $\sqrt{w}$. Then, the WLS estimator is given by $$ \hat{\beta}_{WLS}=\left(\tilde{x}'\tilde{x}\right)^{-1}\tilde{x}'\tilde{y}= \left[(\sqrt{w}x)'\sqrt{w}x\right]^{-1}(\sqrt{w}x)'(\sqrt{w}y)=(x'Wx)^{-1}(xWy) $$ as $\sqrt{w}'\sqrt{w}=W$ and $\tilde{x}=\sqrt{w}x$ which is exactly the same as multiplying each row of $X$ and $y$ by the sqrt of your weight (analytical weight, here $\sqrt{w}$).

The thing here is to understand how your matrix relates to applying the weights and understanding the connection between your formula and the one which is in the help file. For other ways to calculate weighted regressions in relation with Stata, see e.g. this document


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.