# Clustered standard errors

(My research question is economics based, but for simplicity, I'm using a non-economics example)

Suppose I'm trying to find out whether average body temperature of a population is equal to 37 degrees Celsius. I take a random sample of people and take their body temperature.

The problem is, some people have taken their body temperature once, but others have taken their temperature multiple times (twice, thrice, or even ten times).

Ordinarily I would regress body temperature on a constant, and do hypothesis testing with $H_0: \beta_0 = 37$. However, I am worried about serial correlation.

Would clustering the standard errors by person be sufficient to correct for this serial correlation? (e.g. using reg bodytemperature, cluster(person) in Stata)

• Clustering does not in general take care of serial correlation. Furthermore, the way you are suggesting to cluster would imply N clusters with one observation each, which is generally not a good idea. Also, why are you worried about serial correlation in this case? I don't see how the serial correlation in your sample is affected by whether people in the past have ever measured they're temperature and you don't have a panel from what I understand. For questions about clustering, I can highly recommend Cameron and Miller's paper "A Practitioner’s Guide to Cluster-Robust Inference". – BB King Sep 1 '17 at 19:26
• Oops, sorry, I didn't explain clearly. What I meant was that some people have taken their temperature multiple times, and this is recorded in their dataset. For example, if I have my temperature taken five times, then it will be recorded in the dataset as five observations, but with my name next to it. – wwl Sep 1 '17 at 20:16

I am not sure this will answer your question, but let's me try with a concrete example using Stata and its 1978 Automobile Data in order to regress car's price on mileage (mpg).

sysuse auto, clear
reg price mpg, robust

This gives a price estimate of -238.9, with a standard error (s.e) of 57.5. Then, if I run the same regression after duplicating the observations three times.

expand 3
reg price mpg, robust

I get as expected a much lower s.e. of 32.9. Finally, clustering the s.e. by make (a Car Id)

reg price mpg, cluster(make)

gives a s.e. of 57.2 and makes the trick.

However, if you expand twice some observations and thrice others (as in your example). Then, you will get a larger s.e but also a different estimate. But, again, clustering by make reduces the s.e. Here is the code:

sysuse auto, clear
expand 3 if price>4000 & price<=6000
expand 2 if price>6000
reg price mpg, robust
reg price mpg, cluster(make)

Note that the price and mpg variables have been expanded without any change for each car. In your example, if the ones who have taken their temperature multiple times have each time a different temperature, then you may consider introduction an individual fixed effect.

• This is an interesting exercise. However, your expanded sample is not random since you have expanded the sample based on an if condition. If the individuals with multiple temperatures are a random sample of the population, your example is not equivalent. I suggest you try a random expansion, e.g. by creating a variable with a random draw from a uniform between 1 and 3 and then using that variable as fweight. I am looking forward to the see results of that! – luchonacho Oct 13 '17 at 9:32

If you want to stick to OLS, your suggestion (clustering) seems fine. If you want to pursue efficiency, you may want to use the random effects FGLS (xtreg bodytemperature, i(person)) estimation.

If you believe that all body temperatures are identical on average, it is alright to use any of them. But if they are heterogenous (due to genes or whatever), none is satisfactory. I would rather think more about what "average body temperature" means.

Let us take an example. When your population is three people (101, 102, and 103) and your sample is

i      person         x      /* x = measured temp */
1       101         36.5
2       102         36.8
3       102         37.8
4       103         37.5

(note that person 102 is measured twice), I guess what you want is $A=(1/3) \times [E(temp_{101}) + E(temp_{102}) + E(temp_{103}) ]$. OLS (the unweighted average), however, equals $(1/4) \times (x_1 + x_2 + x_3 + x_4)$, which is an unbiased estimator of $B=(1/4) \times [ E(temp_{101}) + E(temp_{102}) + E(temp_{102}) + E(temp_{103}) ]$. If $A = B$, that's fine, but $A$ and $B$ can be different.

When you want $A$, what you want to calculate is $A_{be} = (1/3) \times [x_1 + (x_2 + x_3)/2 + x_4]$, while OLS puts too much weight on person 102. $A_{be}$ is called the panel "between group (BE) estimator". You can get it by xtreg bodytemperature, be i(person).

For the above data set, the BE estimate (of $A$) is 37.1, while the OLS estimate (of $B$) is 37.15. Try the following in Stata (copy & paste).

* Copy & paste into Stata
clear all
input person temp
101 36.5
102 36.8
102 37.8
103 37.5
end
gen temp37 = temp-37
reg temp37, vce(cluster person)
xtreg temp37, be i(person)

(I deliberately subtracted 37 in order to test your null hypothesis.)

I think you are overcomplicating the issue. There is no good reason to believe that the measurement of temperature for the same individual in different times are to be dependent. If the thermometer (or the instrument used to measure temperature) is of good quality, then observations, both over time and across the sample are independent. Therefore, you can treat multiple observations of the same individual as if they were from other individuals. There is no need to cluster. In other words, your sample is $iid$, under which OLS estimates are unbiased and consistent.

If you still believe there is dependence of measurement over time (but you need to argue why), you can indeed use clustering. Comparing the two models would give you an idea of whether the clustering is in fact needed.