|
|
|
||||
|
Help the Stat Consulting Group by
giving a gift
| |||||
|
Loading
|
|||||
If we wanted summary statistics for each ses group, we would need to use sort and then by as illustrated below.use http://www.ats.ucla.edu/stat/stata/notes/hsb2, clear (highschool and beyond (200 cases))
sort ses
by ses: summarize read write
-------------------------------------------------------------------------------------------------------------
-> ses = low
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
read | 47 48.2766 9.342987 28 68
write | 47 50.61702 9.490391 31 65
-------------------------------------------------------------------------------------------------------------
-> ses = middle
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
read | 95 51.57895 9.425609 31 73
write | 95 51.92632 9.106044 31 67
-------------------------------------------------------------------------------------------------------------
-> ses = high
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
read | 58 56.5 10.85834 34 76
write | 58 55.91379 9.442874 33 67
Here is one way to accomplish this with in a single step.
by ses, sort: summarize read write
-------------------------------------------------------------------------------------------------------------
-> ses = low
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
read | 47 48.2766 9.342987 28 68
write | 47 50.61702 9.490391 31 65
-------------------------------------------------------------------------------------------------------------
-> ses = middle
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
read | 95 51.57895 9.425609 31 73
write | 95 51.92632 9.106044 31 67
-------------------------------------------------------------------------------------------------------------
-> ses = high
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
read | 58 56.5 10.85834 34 76
write | 58 55.91379 9.442874 33 67
Alternatively, it is possible to combine by and sort into a single bysort
command. The bysort command looks like this:
bysort ses: summarize read write
-------------------------------------------------------------------------------------------------------------
-> ses = low
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
read | 47 48.2766 9.342987 28 68
write | 47 50.61702 9.490391 31 65
-------------------------------------------------------------------------------------------------------------
-> ses = middle
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
read | 95 51.57895 9.425609 31 73
write | 95 51.92632 9.106044 31 67
-------------------------------------------------------------------------------------------------------------
-> ses = high
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
read | 58 56.5 10.85834 34 76
write | 58 55.91379 9.442874 33 67
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services