However in this way I lose the observations of the IDs that I want to select in other time periods that time =2
I would have loved to send a reproducable example, but the issue is that I am working with data on a secure computer without access to internet (accept Rstudio itself).
I hope may question is clear? If more detail is needed, please let me know.
Hi, @MLent! Thanks for including some of your data. There's a couple things you can do to make it easier for folks here to help with your question. The first is formatting your code as code so it's easier to read and copy and paste into an R console. Basically, you just enclose your code between three back ticks like this:
``` r
reg <- plm(y~x, data=subset(df, ID[Variable>1000]), model="within")
```
Also, to make it easier for folks here to read and work with, it's better to create an R object with your sample data and post it here. This post has some good tips for how to include sample data:
So, with your example, I would do something like the following:
(I added more fake data to make the example a bit more clear.)
To manipulate data, I like to use the the dplyr package, which is part of the tidyverse. It can sometimes be a little more verbose than other ways of coding in R, but I think it makes the code easier to understand!
So here is how I would create a subset of the data you describe. First I find which IDs meet the conditions you define, and then I use those IDs to subset the full dataset.