. . capture program drop muratio
. program define muratio, rclass 1. version 11 2. syntax varlist(min=2 max=2) 3. tempname ymu 4. summarize `1', meanonly 5. scalar `ymu' = r(mean) 6. summarize `2', meanonly 7. return scalar ratio = `ymu'/r(mean) 8. end
. . set seed 10101
. local reps 1000
. webuse auto, clear (1978 Automobile Data)
. tabstat price, by(foreign) stat(n mean semean)
Summary for variables: price by categories of: foreign (Car type)
foreign | N mean se(mean) ---------+------------------------------ Domestic | 52 6072.423 429.4911 Foreign | 22 6384.682 558.9942 ---------+------------------------------ Total | 74 6165.257 342.8719 ----------------------------------------
. g p_dom = price if foreign==0 (22 missing values generated)
. g p_for = price if foreign==1 (52 missing values generated)
. muratio p_dom p_for
. return list
scalars: r(ratio) = .9510925132761489
. . bootstrap r(ratio), reps(`reps') nodots /// > saving(771bs2_9,replace): muratio p_dom p_for
Warning: Because muratio is not an estimation command or does not set e(sample), bootstrap has no way to determine which observations are used in calculating the statistics and so assumes that all observations are used. This means that no observations will be excluded from the resampling because of missing values or other reasons.
If the assumption is not true, press Break, save the data, and drop the observations that are to be excluded. Be sure that the dataset in memory contains only the relevant data.
Bootstrap results Number of obs = 74 Replications = 1000
command: muratio p_dom p_for _bs_1: r(ratio)
------------------------------------------------------------------------------ | Observed Bootstrap Normal-based | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _bs_1 | .9510925 .1072875 8.86 0.000 .7408128 1.161372 ------------------------------------------------------------------------------
. use 771bs2_9,clear (bootstrap: muratio)
. histogram _bs_1, normal name(g771bs2_r, replace) xsize(9) ysize(7) /// > ti("Bootstrap distribution of ratio of means") (bin=29, start=.68787545, width=.02437044)
. . qui graph export 771bstrap1.pdf, replace