Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instrument weights #42

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

bramtayl
Copy link

No idea if I did this right. Closes #41.

@@ -128,16 +128,14 @@ twosls <- function(y, X, W, intercept = FALSE, lm.type = "lm"){

if(intercept) {
model <- switch(lm.type,
"lm" = lm(y ~ Xhat),
"lm.fit" = lm.fit(cbind(1, Xhat), y),
".lm.fit" = .lm.fit(cbind(1, Xhat), y))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure how to weight ".lm.fit". I don't see the ".lm.fit" option being used, and this function isn't exported, so I just deleted it?

if (! is.numeric(w)) stop("'weights' must be a numeric vector")
if (any(w < 0) || anyNA(w)) stop("missing or negative weights not allowed")
X <- X * sqrt(w)
y <- y * sqrt(w)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this because I used lm to weight below and don't want to weight twice.

# also: RE bvk/BE/FE IV do not have weighting code.
if (inst.method == "baltagi") W <- sqrt(w) * cbind(W1, W2, B1)
if (inst.method == "am") W <- sqrt(w) * cbind(W1, W2, B1, StarW1)
if (inst.method == "bms") W <- sqrt(w) * cbind(W1, W2, B1, StarW1, StarW2)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete weights because I used lm to weight below and don't want to weight twice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Help with weights for instrumental variable regression
1 participant