Correctly calculate n_missing_values field when writing variables that