I want to reshape a dataset from long to wide. Every ID has 11 observations and the variables of interest are only in some observations. For example, when I reshape it to wide, it creates 11 variables for varA (varA1,varA2, ..., varA11). But I just need data for varA in 2010 and 2014 (varA1 & varA5). In wide format, I want just two new variables for varA and one variable for varB, etc,..(not 11 for each). My only thought is that when I reshape it to wide, I can check new variables (new columns) and delete them when they don't contain information. But as my dataset is very large, it would be cumbersome. Is there any solution in Stata that I can apply before reshaping to ignore row without information on my variables(or after reshaping when it's wide to delete new variables if they don't contain information)? Thank you in advance.
ID | year | varA | varB | varC | varD |
1 | 2010 | 5 | 4 | ||
1 | 2011 | ||||
1 | 2012 | 4 | 4 | ||
1 | 2013 | ||||
1 | 2014 | 4 | 5 | ||
1 | 2015 | ||||
1 | 2016 | ||||
1 | 2017 | ||||
1 | 2018 | ||||
1 | 2019 | 4 | |||
1 | 2020 | ||||
2 | 2010 | 4 | 5 | ||
2 | 2011 | ||||
2 | 2012 | 3 | 5 |
Comment