19 Immediate commands Contents 19.1 19.2 19.3 19.1 Overview 19.1.1 Examples 19.1.2 A list of the immediate commands The display command The power command Overview An immediate command is a command that obtains data not from the data stored in memory but from numbers typed as arguments. Immediate commands, in effect, turn Stata into a glorified hand calculator. There are many instances when you may not have the data, but you do know something about the data, and what you know is adequate to perform statistical tests. For instance, you do not have to have individual-level data to obtain the standard error of the mean, and thereby a confidence interval, if you know the mean, standard deviation, and number of observations. In other instances, you may actually have the data, and you could enter the data and perform the test, but it would be easier if you could just ask for the statistic based on a summary. For instance, you flip a coin 10 times, and it comes up heads twice. You could enter a 10-observation dataset with two ones (standing for heads) and eight zeros (meaning tails). Immediate commands are meant to solve those problems. Immediate commands have the following properties: 1. They never disturb the data in memory. You can perform an immediate calculation as an aside without changing your data. 2. The syntax for these commands is the same, the command name followed by numbers, which are the summary statistics from which the statistic is calculated. The numbers are almost always summary statistics, and the order in which they are specified is in some sense “natural”. 3. Immediate commands all end in the letter i , although the converse is not true. Usually, if there is an immediate command, there is a nonimmediate form also, that is, a form that works on the data in memory. For every statistical command in Stata, we have included an immediate form if it is reasonable to assume that you might know the requisite summary statistics without having the underlying data and if typing those statistics is not absurdly burdensome. 4. Immediate commands are documented along with their nonimmediate counterparts. Thus, if you want to obtain a confidence interval, whether it be from summary data with an immediate command or using the data in memory, use the table of contents or index to discover that [R] ci discusses confidence intervals. There, you learn that ci calculates confidence intervals by using the data in memory and that cii does the same with the data specified immediately following the command. 1 2 19.1.1 [ U ] 19 Immediate commands Examples Example 1 Let’s take the example of confidence intervals. Professional papers often publish the mean, standard deviation, and number of observations for variables used in the analysis. Those statistics are sufficient for calculating a confidence interval. If we know that the mean mileage rating of cars in some sample is 24, that the standard deviation is 6, and that there are 97 cars in the sample, we can calculate . cii 97 24 6 Variable Obs Mean 97 24 Std. Err. [95% Conf. Interval] .6092077 22.79073 25.20927 We learn that the mean’s standard error is 0.61 and its 95% confidence interval is [ 22.8, 25.2 ]. To obtain this, we typed cii (the immediate form of the ci command) followed by the number of observations, the mean, and the standard deviation. We knew the order in which to specify the numbers because we had read [R] ci. We could use the immediate form of the ttest command to test the hypothesis that the true mean is 22: . ttesti 97 24 6 22 One-sample t test x Obs Mean 97 24 mean = mean(x) Ho: mean = 22 Ha: mean < 22 Pr(T < t) = 0.9993 Std. Err. Std. Dev. .6092077 6 [95% Conf. Interval] 22.79073 25.20927 t = 3.2830 degrees of freedom = 96 Ha: mean != 22 Ha: mean > 22 Pr(|T| > |t|) = 0.0014 Pr(T > t) = 0.0007 The first three numbers were as we specified in the cii command. ttesti requires a fourth number, which is the constant against which the mean is being tested; see [R] ttest. Example 2 We mentioned flipping a coin 10 times and having it come up heads twice. The 99% confidence interval can also be obtained from ci: . cii 10 2, level(99) Variable Obs Mean 10 .2 Std. Err. Binomial Exact [99% Conf. Interval] .1264911 .0108505 .6482012 In the previous example, we specified cii with three numbers following it; in this example, we specify 2. Immediate commands often determine what to do by the number of arguments following the command. With two arguments, ci assumes that we are specifying the number of trials and successes from a binomial experiment; see [R] ci. [ U ] 19 Immediate commands 3 The immediate form of the bitest command performs exact hypothesis testing: . bitesti 10 2 .5 N Observed k Expected k 10 2 5 Pr(k >= 2) = 0.989258 Pr(k <= 2) = 0.054688 Pr(k <= 2 or k >= 8) = 0.109375 Assumed p Observed p 0.50000 (one-sided test) (one-sided test) (two-sided test) 0.20000 For a full explanation of this output, see [R] bitest. Example 3 Stata’s tabulate command makes tables and calculates various measures of association. The immediate form, tabi, does the same, but we specify the contents of the table following the command: . tabi 5 10 \ 2 14 row 1 2 Total col 1 5 2 7 Fisher’s exact = 1-sided Fisher’s exact = 2 Total 10 14 15 16 24 31 0.220 0.170 The tabi command is slightly different from most immediate commands because it uses ‘\’ to indicate where one row ends and another begins. 4 [ U ] 19 Immediate commands 19.1.2 A list of the immediate commands Command Reference Description bitesti [R] bitest Binomial probability test cci csi iri mcci [ST] epitab Tables for epidemiologists cii [R] ci Confidence intervals for means, proportions, and counts esizei [R] esize Effect size based on mean comparison prtesti [R] prtest Tests of proportions sdtesti [R] sdtest Variance comparison tests symmi [R] symmetry Symmetry and marginal homogeneity tests tabi [R] tabulate twoway Two-way tables of frequencies ttesti [R] ttest Mean comparison tests twoway pci twoway pcarrowi twoway scatteri [G-2] graph twoway pci [G-2] graph twoway pcarrowi [G-2] graph twoway scatteri Paired-coordinate plot with spikes or lines Paired-coordinate plot with arrows Twoway scatterplot 19.2 The display command display is not really an immediate command, but it can be used as a hand calculator. . display 2+5 7 . display sqrt(2+sqrt(3^2-4*2*-2))/(2*3) .44095855 See [R] display. 19.3 The power command power is not technically an immediate command because it does not do something on typed numbers that another command does on the dataset. It does, however, work strictly on numbers you type on the command line and does not disturb the data in memory. power performs power and sample-size analysis. See Stata Power and Sample-Size Reference Manual.