📄 sample.hlp
字号:
{smcl}
{* 23feb2005}{...}
{cmd:help sample}{right:dialog: {bf:{dialog sample}}}
{hline}
{title:Title}
{p2colset 5 19 21 2}{...}
{p2col :{hi:[D] sample} {hline 2}}Draw random sample{p_end}
{p2colreset}{...}
{title:Syntax}
{p 8 15 2}
{cmd:sample}
{it:#}
{ifin}
[{cmd:,} {opt c:ount} {opt by(groupvars)}]
{p 4 6 2}
{opt by} may be used with {opt sample}; see {helpb by}.
{p_end}
{title:Description}
{pstd}
{opt sample} draws random samples of the data in memory. "Sampling" here is
defined as drawing observations without replacement; see {helpb bootstrap}
for sampling with replacement.
{pstd}
The size of the sample to be drawn can be specified as a percent or as a
count:
{pin}
{opt sample} without the {opt count} option draws a {it:#} percent
pseudorandom sample of the data in memory, thus discarding 100 - {it:#}
percent of the observations.
{pin}
{opt sample} with the {opt count} option draws a {it:#}-observation
pseudorandom sample of the data in memory, thus discarding {cmd:_N} - {it:#}
observations. {it:#} can be larger than {help _N}, in which case all
observations are kept.
{pstd}
In either case, observations not meeting the optional {opt if} and {opt in}
criteria are kept (sampled at 100%).
{pstd}
If you are interested in reproducing results, you must first set the
random-number seed; see {helpb generate}.
{title:Options}
{phang}
{opt count} specifies that {it:#} in {opt sample} {it:#} be
interpreted as an observation count rather than as a percentage. Typing
{opt sample 5} without the {opt count} option means that a 5% sample be
drawn; typing {opt sample 5, count}, however,
would draw a sample of 5 observations.
{pmore}
Specifying {it:#} as greater than the number of observations in the dataset
is not considered an error.
{pmore}
{opt count} may be combined with the {opt by} prefix;
e.g., {cmd:by sex: sample 50, count} would draw a sample of size 50 for
men and 50 for women.
{phang}
{opt by(groupvars)} specifies that a {it:#}-percent sample be drawn within
each set of values of {it:groupvars}, thus maintaining the proportion of
each group.
{title:Examples}
{p2colset 5 37 39 2}{...}
{p2col :{cmd:. sample 10}}(draw 10% sample){p_end}
{p2col :{cmd:. sample 10 if race==0}}(keep all race!=0,
but sample 10% of race==0){p_end}
{p2col :{cmd:. by race: sample 10}}(sample 10% of each race)
{p2col :{cmd:. sample 50, count}}(draw 50-obs. sample){p_end}
{p2col :{cmd:. sample 50 if race==0, count}}(keep all race!=0,
but sample 50 obs. of race==0){p_end}
{p2col :{cmd:. by race: sample 50, count}}(sample 50 obs. of each race)
{p2colreset}{...}
{title:Also see}
{psee}
Manual: {bf:[D] sample}
{psee}
Online: {helpb bootstrap}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -