Hi all
First time posting (sorry in advance for any mistakes in how to post, will edit of course!)
I am having an issue using the collapse command for a large dataset of ~700,000 observations across 15,000 people. Each observation is for a person with a given pain score. I want to find the average per person. Each person has a different number of pain scores in the dataset (some have <5 and some have >100).
The code I used is below
collapse pain_score by (person)
This seems to work and correctly collapses the dataset to the correct number of people with a given average for pain score for each person. However, when I spot check a few people, the averages are all slightly off. For example, Person 1 has 6 observations which are 6, 6, 0, 0, 0, 0 which should be an average of 2, but the mean in Stata is 2.333. There are similar discrepancies throughout.
Thank you in advance!
First time posting (sorry in advance for any mistakes in how to post, will edit of course!)
I am having an issue using the collapse command for a large dataset of ~700,000 observations across 15,000 people. Each observation is for a person with a given pain score. I want to find the average per person. Each person has a different number of pain scores in the dataset (some have <5 and some have >100).
The code I used is below
collapse pain_score by (person)
This seems to work and correctly collapses the dataset to the correct number of people with a given average for pain score for each person. However, when I spot check a few people, the averages are all slightly off. For example, Person 1 has 6 observations which are 6, 6, 0, 0, 0, 0 which should be an average of 2, but the mean in Stata is 2.333. There are similar discrepancies throughout.
Thank you in advance!

Comment