1. Basics
- 加载dataset - use ''path\to\file''
- 清除dataset - clear
- 简单运算 - display
- 变量的储存 - scalar
- 变量的清除 - scalar drop
- 查看dataset - browse
- 帮助 - help command
Exercise 1: Compute √24 and save it as y
. Compute y^3 and save it as z
. View z
to ensure it is saved correctly. z
should equal 117.57551.
scalar y = sqrt(24)
scalar z = y^3
diplay z
- summarize variable, detail
2. Distribution
2.1 Discrete value distribution:
Binomial probabilities:
display binomialp(n,x,p)
- gives P(X=x)
display binomial(n,x,p)
- gives P(X<=x)
display binomialtail(n,x,p)
- gives P(X>=x)
Poisson probabilities:
display poissonp(u,x)
- gives P(X=x)
display poisson(u,x)
- gives P(X<=x)
display poissontail(u,x)
- gives P(X>=x)
2.2 Continuous value distribution:
Normal distribution probabilities:
For Z~ N(0,1)
display normal(1.96)
output:0.9750021
Note that the command is used to calculate P(Z<=k), which is P(Z<=1.96) in the example above.
3. Confidence Interval
3.0 critical values
- normal distribution
display invnormal(0.975)
- t distribution:
t_n-1,0.975,
n-1 = 89 degrees of freedom
display invt(89,0.975)
- p value for F distribution
display Ftail(df1, df2, f)
3.1 Confidence Interval for a Mean
ci mean VariableName
default level 95%
ci mean VariableName, level(90)
for level 90%cii mean N SampMean StDev
N - # observations
SampMean - sample mean
StDev - sample standard deviation
3.2 Exact Binomial CI
- For a dataset:
95% CI
ci proportion variableName
99% CI
ci proportion variableName, level(99)
- For immediate result without an underlying dataset:
cii proportion Denominator Numerator
Numerator: number of successes
Denominator: number of individual in the group of interests
3.3 Exact Poisson CI
cii means t x, poisson
t - exposure time
x - number of observed events
4. Hypothesis testing
4.1 One Sample Test for a mean
one sample t-test:
ttest fulliq=100 if group ==1
ttest edu = 14, level(90)
ttesti n x s u0
ex: ttesti 46 88.02 12.21 100
n - # observations - 46
x - sample mean - 88.02
s - sample standard deviation - 12.21
u0 - null value of the mean - 100
4.2 One Sample Test for a Proportion
prtesti n p^ p0
ex prtesti 100 0.13 0.1
n - sample size
p^ - sample proportion
p0 - null hypothesis value
Exact Binomial Test
bitesti n x p0
n - number of sample
x - incident cases
p0 - population p
4.3 power and sample size
to get power:
sampsi u0 u1, onesample n(#) sd(\sigma) alpha(0.05)
to get sample size:
sampsi u0 u1, onesample sd(\sigma) power(0.80) alpha(0.05)
For proportion,
p0 and p1 take the place of u0, u1
4.4 two-sample paired t-test
ttest variable1 = variable2