Hi there,
I want to create several variables that store the mean of other "mother" variables (trunk and displacement) for different values of an index variable (rep 78). Then I want to estimate the difference between means, also for the different levels of the index value. I used the following code:
As you can see, the output displays the summaries of trunk and displacement for the different values of rep78. But it only displays the means difference for rep78=3. Why?
I want to create several variables that store the mean of other "mother" variables (trunk and displacement) for different values of an index variable (rep 78). Then I want to estimate the difference between means, also for the different levels of the index value. I used the following code:
Code:
sysuse auto, clear
drop if missing(rep78)
levelsof rep78,local(levels)
foreach l of local levels {
summarize trunk displacement if rep78 == `l'
egen disp_`l'= mean(displacement) if rep78 == `l'
egen trunk_`l'= mean(trunk) if rep78 == `l'
gen dif_`l'= disp_`l' - trunk_`l'
di dif_`l'
}
As you can see, the output displays the summaries of trunk and displacement for the different values of rep78. But it only displays the means difference for rep78=3. Why?
Comment