
The results show that for id, the missing value (.) for x1 in the second row of input data has been treated as a zero, producing a summed value of zero. The results from your -list- command should look like the figure below. If you are willing to treat missing values as zeros, then using the standard -collapse- command and sum() function is fine.Įntering the following syntax in Stata demonstrates this.
Hybrid approach: differentiate between missing and other values, such as zeros. Evaluate collapse sums with any missing values as missing. Treat the missings as zeros: what the standard collapse command does. Most of us will run into this kind of scenario eventually.įortunately, there are a finite number of ways to deal with the problem: If you’ve never encountered this quandary before, then count yourself lucky. But, this does not always mean it is acceptable to treat the missing data as a zero. For example, a missing value might occur due to survey nonresponse by a respondent. This can be a serious problem if zeros and missing values are substantively different in your data. The basic issue is in the way sum() treats missing data namely, the missing values evaluate to zero. One of those quirks shows up when using the -collapse- command and the sum() function. Like any program, Stata certainly has its quirks. How Do I Get Stata to Treat Missing Values The Way I Want? In this article, I show three ways Stata can treat missing values when using the -collapse- command and the sum() function. Even the most seasoned Stata users get bit by this quirk every once in a while.
It replaced all of the missing values in your data set with zeros!īut that’s not at all what you wanted! You wanted those to be missing values, not zeros. That -collapse- command you issued a while back did something rather odd. Your finely-tuned debugging skills kick in, and you track down the problem.
The data begin looking like something from one of Lord Voldemort’s nightmares. That 3-day project you started this morning might actually be completed by the end of the day.Īs your fingers fly across the keyboard, you think you can hear Stata singing your praise softly in the background.
Stata collapse free#
© Soldeandalucia | Stock Free Images & Dreamstime Stock Photos