Prepare Data: Manage Observations

Learn how to manage observations and how to remove specific observations.

Remove select observations

Sometimes, we want to remove select observations that satisfy certain conditions. The easiest solution is to apply logical operators and the indexing method to a dataset. Take the dataset pwt7 as an example. There are two versions of GDP data for China in the dataset. These versions are based on different price data, one official and the other nonofficial. Thus, for the same years for China, one set of observations is denoted by iso code CHN, and another set by iso code CH2. In data analysis, it’s not ideal to include both sets of observations at the same time. The code below demonstrates a simple method to remove all the observations where isocode equals CH2 and save the output into a new dataset, pwt7.nc.

Get hands-on with 1200+ tech skills courses.