R Notes

Puzzle of Conditions in dplyr

Puzzle I am not sure how do I condition on whether a value in column A appears in column B? I use the naive way value A %in% column B within a mutate function. It workers such that R would search all values in column B. What’s more, it even works within groups. However, I not sure whether it is a luck or a right way to do it? Example library(dplyr, warn.

Notes on the Constant Term in the Fixed Effect Model

In stata, the fixed effect model(xtreg y x1 x2 x3, fe) report a constant term. The underline estimate is [y{it} - \bar{yr} + \bar{\bar{y}} = a + (x{it} - \bar{x{i}} + \bar{\bar{x}})) \alpha + (\epsilon{it} - \bar{e_i} + \bar{v})] with the constrant (\bar{v}) equals to 0. Details can be found on Stata’s website. In R, plm package does not calculate the some whate artificial1 intercept for within models. see help(“within_intercept”, package = “plm”)↩