long_panel() is imputing incorrect value
Hello,
I'm working with multi-level data, and something strange is happening with one variable when I use long_panel().
Here is my code:
caps.long<-as.data.frame(long_panel(caps.wide, prefix = "a", begin = 1, end = 4, label_location = "beginning", as_panel_data=FALSE))

The variable that isn't behaving is serology-- it seems to be perpetuating 1 from samples 06D1 and 06D2 to 06C1, even though this should be NA. It's happening for more rows than this.
Many thanks, Julianne
you need to set an additional argument:
check.varying = FALSE
because your only two non-NA observations of serology are both 1, which trick the function to think it's time-invariant, so it simply fills the "gaps". Since you don't want panel data at all, there is no need to check varying at all either.
This actually questions the logic of the function--why convert to panel_data first and then unpanel? Isn't it more logical to check the as_panel_data argument first before converting?
As @groverlynn said, this is working "properly" in the sense that the function treats measures in which all units have a single non-missing value as non-varying since this is consistent with how the statistical models in the package treat variance. And it is an option, as stated, to tell this function not to automatically detect whether variables vary over time (this has the side effect of speeding things up a lot with even medium-sized datasets). I am thinking of letting the user specify themselves specific variables to treat as varying regardless of how it looks by this automatic method.
Also, @groverlynn your observation about the sequence of events at the end of the function is correct. If the user does not want me to check for whether variables vary and does not want a panel_data object returned, the conversion to panel_data and back is redundant. I'm pushing a change to that effect on the off chance it can speed things up for people or avoid some unforeseen bug when converting.