Skip to content

Commit

Permalink
+ Iteration for IFE julia routines now passed from argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Loualiche committed Jul 6, 2019
1 parent 459af61 commit 5d55284
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions R/FixedEffectInteract.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#' @param fe expression of fixed effects id1 + id2:id3
#' @param weights expression of weights
#' @param vcov Specification for the error
#' @param maxiter Parameter that passes to julia the solver max iteration
#' @param timing Add timing
#' @param save_res Save the results of the model
#' @param print do we print output or not
#'
Expand All @@ -36,10 +38,13 @@ FixedEffectInteract <- function(
fe = NULL,
weights = NULL,
vcov = NULL,
maxiter = 10000L,
timing = TRUE,
save_res = TRUE, # do we save PCs, loadings and fixed effects
print = TRUE
){

# initialize
setDT(dt)

# parse the rhs, fe and cluster
Expand Down Expand Up @@ -96,7 +101,7 @@ FixedEffectInteract <- function(

julia_regcall = paste("reg_res = regife(df_julia, @model(",
paste(c(julia_formula, julia_ife, julia_reg_opt), collapse = ", "),
") );")
"), maxiter =", as.integer(maxiter), ");")
julia_regcall <- gsub(", ,", ",", julia_regcall) # clean up because of missing instructions (e.g. when no fe are specified)

# ---------------------------------
Expand Down Expand Up @@ -145,18 +150,29 @@ FixedEffectInteract <- function(


# ----------------------------
# Managing exceptions in julia
# Managing exceptions in julia
# initialize:
julia_command("reg_res = (augmentdf=0, coefnames=0);")
julia_regcall_exception = gsub("reg_res = ", "", julia_regcall)
julia_regcall_exception = paste0("reg_res = try ", julia_regcall_exception, "catch; (augmentdf=0, coefnames=0) end;")
julia_regcall = julia_regcall_exception
julia_regcall = julia_regcall_exception;
if (timing == TRUE){
julia_regcall = paste("@time", julia_regcall);
}
# ----------------------------

# ----------------------------
if (print==TRUE){
message(julia_regcall)
}
# Run the regression
julia_command(julia_regcall)
try(julia_command(julia_regcall))
#tryCatch(julia_command(julia_regcall),
# error = function(c) "IFE error",
# warning = function(c) "IFE warning",
# message = function(c) "IFE message"
#)

# ----------------------------

# ----------------------------
Expand Down

0 comments on commit 5d55284

Please sign in to comment.