0

I have two panel data sets that are mergeable. However, I have to create bins of time as both data sets are highly imbalanced and have highly variable measurement occasions.

One approach is the following:

    panel_df1_monthly <- panel_df1 %>%
    mutate(TimeMetric_Monthly = floor_date(TimeVariable, unit = "month")) %>%
    group_by(ID, TimeMetric_Monthly) %>%
    summarize(Monthly_Avg_Value1 = mean(Value1, na.rm = TRUE))  
    panel_df2_monthly <- panel_df2 %>%
    mutate(TimeMetric_Monthly = floor_date(TimeVariable, unit = "month")) %>%
    group_by(ID, TimeMetric_Monthly) %>%
    summarize(Monthly_Avg_Value2 = mean(Value2, na.rm = TRUE)) 

However, regardless of the time metric chosen (e.g., month, quarter), the aggregated statistic is the same. The value should vary depending on the time metric and the new data sets (e.g., panel_df1_monthly, panel_df1_quarterly) should look different, with a column for the new time metric and another column with it's corresponding value for another variable. Here, all the new panel datasets look alike.

I have also tried other approaches, but these do not produce harmonizable panel datasets the new time metrics do not align across them.

3
  • 1
    Can you post sample data? Make cols <- c("ID", "TimeVariable", "Value1") and please edit the question with the output of dput(df[cols]). Or, if it is too big with the output of dput(head(df[cols], 20)). Commented Dec 23, 2023 at 17:41
  • 1
    Is the summarization happening by group? Sometimes people encounter unexpected behavior with grouped data sets because they have loaded the plyr package, which has a summarize function which does not see groupings. Commented Dec 24, 2023 at 0:51
  • I don't know if this is about the summarization or the visualization. If you say the facets do not align, then it could be either. Please add sample data, plotting code, an image, and explain what is wrong about the image. Perhaps it's not about the plot, but since you mentioned it I think it's worth taking a look at it. (See stackoverflow.com/q/5963269 , minimal reproducible example, and stackoverflow.com/tags/r/info for discussions about reproducibility, please.) Commented Dec 24, 2023 at 12:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.