R/create_dyadic_fe.R

Defines functions create_dyadic_fe

#' Create dyadic fixed effects
#'
#' @param x an object of class \code{matrix}: adjacency matrix.
#' @return an object of class \code{data.frame} containing fixed effect for both \emph{i} and \emph{j}.
#' @keywords internal
#' @noRd
create_dyadic_fe <- function(x){
  x <- as.matrix(x)
  ridx <- c(apply(x, 1, function(z) rep(z, length(x))))
  cidx <- rep(x, length(x))
  fixed <- cbind(ridx, cidx)
  fixed <- fixed[ - which(fixed[, 1] == fixed[, 2]), ]
  return(fixed)
}

Try the econet package in your browser

Any scripts or data that you put into this service are public.

econet documentation built on April 28, 2022, 1:07 a.m.