Am 22.07.2022 um 21:08 schrieb Sven Schreiber:
The coefficients agree exactly with those from your function.
Now, I haven't cross-checked the standard errors there with Stata or
anything. I tend to think they should be right, but I'm not certain.
Maybe you could have another look.
I remembered that I have Stata on this machine, so I cross-checked with
the help of your nice foreign-invoking script. If i add the --robust
option to my weighted tsls variant, then I get exactly Stata's output,
including the standard errors for inference (well, except the R2, as
expected).
So to sum up, here's an example how to do weighted IV regression in gretl:
<hansl>
nulldata 128
# artificial input data
y = normal()
x = normal()
z1 = normal()
z2 = normal()
# artificial weighting
wt = exp(normal())
# root normalized weights
series w_factor = sqrt(wt / mean(wt))
# multiply to each variable (including the constant!)
loop foreach i const y x z1 z2
series $i_w = w_factor * $i
endloop
list Xw = const_w x_w
list Zw = const_w z1_w z2_w
# run IV on the weighted data
tsls y_w Xw ; Zw --no-tests --robust
</hansl>
Again, disregard the R2 and related statistics in the output.
In principle this could be put in a function like Jack did with the
2-stage wls approach, then could be packaged up to also treat stuff like
the variable names properly and so on. Plus perhaps calculate a correct
R2. But the econometrics as such is in the few lines above.
cheers
sven