📄 twoway_kdensity.hlp
字号:
{smcl}
{* 08apr2005}{...}
{cmd:help twoway kdensity} {right:dialogs: {dialog twoway_overlay:overlaid twoway}{space 0}}
{right:{dialog twoway_simple:single twoway}{space 2}}
{hline}
{title:Title}
{p2colset 5 34 36 2}{...}
{p2col :{hi:[G] graph twoway kdensity} {hline 2}}Kernel density plots{p_end}
{p2colreset}{...}
{title:Syntax}
{p 8 32 2}
{cmdab:tw:oway}
{cmd:kdensity}
{it:varname}
{ifin}
{weight}
[{cmd:,}
{it:options}]
{p2colset 9 30 32 2}{...}
{it:options}{col 30}description
{p2line}
{cmdab:w:idth:(}{it:#}{cmd:)}{...}
{col 30}smoothing parameter
{cmdab:ep:an}{...}
{col 30}use Epanechnikov kernel; the default
{cmdab:epan2}{...}
{col 30}use alternative Epanechnikov kernel
{cmdab:bi:weight}{...}
{col 30}use biweight kernel
{cmdab:cos:ine}{...}
{col 30}use cosine kernel
{cmdab:gau:ss}{...}
{col 30}use Gaussian kernel
{cmdab:par:zen}{...}
{col 30}use Parzen kernel
{cmdab:rec:tangle}{...}
{col 30}use rectangular kernel
{cmdab:tri:angle}{...}
{col 30}use triangular kernel
{cmdab:ra:nge:(}{it:#} {it:#}{cmd:)}{...}
{col 30}range for plot, minimum and maximum
{opth ra:nge(varname)}{...}
{col 30}range for plot obtained from {it:varname}
{cmd:n(}{it:#}{cmd:)}{...}
{col 30}number of points to evaluate
{cmd:area(}{it:#}{cmd:)}{...}
{col 30}rescaling parameter
{cmdab:hor:izontal}{...}
{col 30}graph horizontally
INCLUDE help gr_clopt
INCLUDE help gr_axlnk
INCLUDE help gr_twopt
{p2line}
{phang}
{cmd:fweight}s and {cmd:aweight}s are allowed; see {help weight}.
{title:Description}
{pstd}
{cmd:graph} {cmd:twoway} {cmd:kdensity} plots a kernel density estimate for
{it:varname} using {cmd:graph} {cmd:twoway} {cmd:line}.
{title:Options}
{phang}
{cmd:width(}{it:#}{cmd:)}
and
{cmd:epan},
{cmd:epan2}, ...,
{cmd:triangle}
specify how the kernel density estimate is to be obtained and are in fact
the same options as those specified with the command {cmd:kdensity}; see
{helpb kdensity}.
{pmore}
{cmd:width(}{it:#}{cmd:)}
specifies the smoothing parameter.
{pmore}
{cmd:epan},
{cmd:epan2}, ...,
{cmd:triangle}
are alternatives and
specify the kernel-weight function to be used.
{cmd:epan} (Epanechnikov) is the default.
{pmore}
See {helpb kdensity} for more information about these options.
{pmore}
All the other {cmd:graph} {cmd:twoway} {cmd:kdensity} options modify how
the result is displayed, not how it is obtained.
{phang}
{cmd:range(}{it:#} {it:#}{cmd:)}
and
{opth range(varname)}
specify the range of values at which the kernel density estimates are
to be plotted. The default is {bind:{cmd:range(}{it:m} {it:M}{cmd:)}},
where {it:m} and {it:M} are the minimum and maximum of the {it:varname}
specified on the {cmd:graph} {cmd:twoway} {cmd:kdensity} command.
{pmore}
{cmd:range(}{it:#} {it:#}{cmd:)}
specifies a pair of numbers to be used as the minimum and maximum.
{pmore}
{cmd:range(}{it:varname}{cmd:)}
specifies another variable for which its minimum and maximum are to be
used.
{phang}
{cmd:n(}{it:#}{cmd:)}
specifies the number of points at which the estimate is evaluated. The
default is {cmd:n(300)}.
{phang}
{cmd:area(}{it:#}{cmd:)}
specifies a multiplier by which the density estimates are adjusted before
being plotted. The default is {cmd:area(1)}. {cmd:area()} is useful when
overlaying a density estimate on top of a histogram that is itself not
scaled as a density. For instance, if you wished to scale the density
estimate as a frequency, {cmd:area()} would be specified as the total
number of nonmissing observations.
{phang}
{cmd:horizontal}
specifies that the result be plotted horizontally (i.e, reflected along
the identity line).
{phang}
{it:cline_options}
specify how the density line is rendered and its appearance;
see {it:{help cline_options}}.
INCLUDE help gr_axlnkf
INCLUDE help gr_twoptf
{title:Remarks}
{pstd}
{cmd:graph} {cmd:twoway} {cmd:kdensity} {it:varname} uses the {cmd:kdensity}
command to obtain an estimate of the density of {it:varname} and uses
{cmd:graph} {cmd:twoway} {cmd:line} to plot the result.
{pstd}
Remarks are presented under the headings
{help twoway kdensity##remarks1:Typical use}
{help twoway kdensity##remarks1:Use with by}
{marker remarks1}{...}
{title:Typical use}
{pstd}
The density estimate is often graphed on top of the histogram:
{cmd:. sysuse lifeexp, clear}
{cmd:. tw histogram lexp, color(*.5) || kdensity lexp}
{it:({stata "gr_example lifeexp: tw histogram lexp, color(*.5) || kdensity lexp":click to run})}
{* graph gtkden1}{...}
{* fill areas, dimming and brightening}{...}
{* index colors, dimming and brightening}{...}
{* index color() tt option}{...}
{* index color intensity adjustment}{...}
{* index intensity, color, adjustment}{...}
{pstd}
Notice the use of {cmd:graph} {cmd:twoway} {cmd:histogram}'s
{cmd:color(*.5)} option to dim the bars and make the line stand out;
see {it:{help colorstyle}}.
{pstd}
Notice also the {it:y} and {it:x} axis titles: "Density/kdensity lexp" and
"Life expectancy at birth/x". The "kdensity lexp" and "x" were contributed by
the {cmd:twoway} {cmd:kdensity}. When you overlay graphs, you nearly always
need to respecify the axis titles using the {it:axis_title_options}
{cmd:ytitle()} and {cmd:xtitle()}; see {it:{help axis_title_options}}.
{marker remarks2}{...}
{title:Use with by}
{pstd}
{cmd:graph} {cmd:twoway} {cmd:kdensity} may be used with {cmd:by()}:
{cmd:. sysuse lifeexp, clear}
{phang2}
{cmd:. tw histogram lexp, color(*.5) || kdensity lexp ||, by(region)}
{p_end}
{it:({stata "gr_example lifeexp: tw histogram lexp, color(*.5) || kdensity lexp ||, by(region)":click to run})}
{* graph gtkden2}{...}
{title:Also see}
{psee}
Manual: {bf:[G] graph twoway kdensity}
{psee}
Online:
{helpb kdensity};
{helpb twoway histogram}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -