AdaemmerP / lpirfs

40 stars 21 forks source link

bug in function `create_lin_data.R`? #30

Closed liuhaiqinFDU closed 1 year ago

liuhaiqinFDU commented 1 year ago

Have you encountered the following error: while running the 81st line yx_all <- cbind(y_lin, x_lin) %>% stats::na.omit()

it gives the yx_all data.frame with inconsistent length with x_lin, then, when the program proceeds to line 101 (suppose I choose to use 2SLS), it will report an error saying "Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: X, Y", where X is the length of my instrument data, which is of the same length as y_lin and x_lin before running the 81st line; Y is the length of yx_all. I think the problem lies in the fact that we drop NAs in the 81st line. How should we fix this?

(I attach my data and my code of using the lp_lin_iv function here) example.zip

liuhaiqinFDU commented 1 year ago

Also, I found that in lp_lin_iv.R, in the 570th (or so) line, the names(diagnostic_list) <- paste("Endog. Variable:", specs$column_names , sep = " ") can encounter error because diagnostic_list is empty before the assignment, maybe adding a line diagnostic_list <- vector("list", length = length(specs$column_names)) before this can fix this problem?

AdaemmerP commented 1 year ago

This is not a bug. Your data contains NA values in between, and the package does not know what to do with them because it does not do automatic imputation. If you remove the NAs, it works. However, you get another error, because of singularity issues. This has something to do with your instruments. Try them out separately.

# Find NA values
data |> 
  mutate(row_nr = row_number()) |> 
  relocate(row_nr) |>
  filter(if_any(everything(), is.na))

# Remove NA values
data <- data
    drop_na()