Agriculture Reference
In-Depth Information
command to summarize with
by
or if unsorted use the
bysort
pre-
fix command. The
by
is implemented as
by
varlist
:
summarize
[
varlist
]
, where the first
varlist
is the grouping variable, in our
case the varieties, while the second
varlist
is the variable to be
computed, in our case the plot yield. There are a number of options
available after the comma including
detail
that calculates several
additional statistics. Below is an example of the output.
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------
fieldyield | 120 93.82417 27.04157 41.7 214.8
summarize
saves results in
r()
, which are specific variables for
results of the most recent calculation. Commands that save in
r()
are called r-class commands. To see what these results are, type
return list
in the Command window immediately after entering
a
summarize
command. The listed variables and their values will be
shown in the Results window.
scalars:
r(N) = 120
r(sum_w) = 120
r(mean) = 93.82416639328002
r(Var) = 731.2465641339238
r(sd) = 27.04157103671907
r(min) = 41.70000076293945
r(max) = 214.8000030517578
r(sum) = 11258.8999671936
If you use the
by
prefix command, in this case the var variable,
only the last calculation will have r() results listed—in this case, for
variety Sapelo Sweet. As long as you do not enter another command
that will overwrite these values, they are available for use in other
calculations. These calculations also can be displayed immediately in
the Results window with a new command
display
. Therefore, for
example, you can calculate the standard error of the mean by taking
the square root of the variance divided by the number of observations.
To do this, enter the following command:
display sqrt
(r(Var)/r(N))
Search WWH ::
Custom Search