全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
4084 5
2015-07-25
假如方程为y=x+x^2+x^3,那么这个图该怎么用stata画呢,我看好多都是二次项的拟合,但是这样的函数该怎么画出来呢~~~
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-7-25 20:03:45
http://www.fight-entropy.com/2013/01/plot-polynomial-of-any-degree-in-stata.html
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-7-25 20:54:11
twoway function y=x+x^2+x^3, range(-50 50)
Graph.png

stata的manual和作图的书上都讲了。
可惜就是不看
这样自己是学不会stata



Title

    [G-2] graph twoway function -- Twoway line plot of function


Syntax

        twoway function [[y]=] f(x) [if] [in] [, options]

    options               Description
    --------------------------------------------------------------------------------------------
    range(# #)            plot over x = # to #
    range(varname)        plot over x = min to max of varname
    n(#)                  evaluate at # points; default is 300

    droplines(numlist)    draw lines to axis at specified x values
    base(#)               base value for dropline(); default is 0

    horizontal            draw plot horizontally

    yvarformat(%fmt)      display format for y
    xvarformat(%fmt)      display format for x

    cline_options         change look of plotted line

    axis_choice_options   associate plot with alternative axis

    twoway_options        titles, legends, axes, added lines and text, by, regions, name, aspect
                            ratio, etc.
    --------------------------------------------------------------------------------------------
    All explicit options are rightmost, except horizontal, which is unique; see repeated
      options.
    if exp and in range play no role unless option range(varname) is specified.
    In the above syntax diagram, f(x) stands for an expression in terms of x.


Menu

    Graphics > Twoway graph (scatter, line, etc.)


Description

    twoway function plots y = f(x), where f(x) is some function of x.  That is, you type

        . twoway function y=sqrt(x)

    It makes no difference whether y and x are variables in your data.


Options

    range(# #) and range(varname) specify the range of values for x.  In the first syntax,
        range() is a pair of numbers identifying the minimum and maximum.  In the second syntax,
        range() is a variable name, and the range used will be obtained from the minimum and
        maximum values of the variable.  If range() is not specified, range(0 1) is assumed.

    n(#) specifies the number of points at which f(x) is to be evaluated.  The default is
        n(300).

    droplines(numlist) adds dropped lines from the function down to, or up to, the axis (or
        y=base() if base() is specified) at each x value specified in numlist.

    base(#) specifies the base for the droplines().  The default is base(0).  This option does
        not affect the range of the axes, so you may also want to specify the axis_scale_option
        yscale(range(#)) as well; see [G-3] axis_scale_options.

    horizontal specifies that the roles of y and x be interchanged and that the graph be plotted
        horizontally rather than vertically (that the plotted function be reflected along the
        identity line).

    yvarformat(%fmt) and xvarformat(%fmt) specify the display format to be used for y and x.
        These formats are used when labeling the axes; see [G-3] axis_label_options.

    cline_options specify how the function line is rendered; see [G-3] cline_options.

    axis_choice_options associate the plot with a particular y or x axis on the graph; see [G-3]
        axis_choice_options.

    twoway_options are a set of common options supported by all twoway graphs.  These options
        allow you to title graphs, name graphs, control axes and legends, add lines and text,
        set aspect ratios, create graphs over by() groups, and change some advanced settings.
        See [G-3] twoway_options.


Remarks

    Remarks are presented under the following headings:

        Typical use
        Advanced use 1
        Advanced use 2


Typical use

    You wish to plot the function y=exp(-x/6)sin(x) over the range 0 to 4pi:

        . twoway function y=exp(-x/6)*sin(x), range(0 12.57)
          (click to run)

    A better rendition of the graph above is

        . twoway function y=exp(-x/6)*sin(x), range(0 12.57)
                yline(0, lstyle(foreground))
                xlabel( 0
                        3.14 "{&pi}"
                        6.28 "2{&pi}"
                        9.42 "3{&pi}"
                       12.57 "4{&pi}")
                plotregion(style(none))
                xsca(noline)
          (click to run)

    yline(0, lstyle(foreground)) added a line at y=0; lstyle(foreground) gave the line the same
    style as used for the axes.  See [G-3] added_line_options.

    xlabel(0 3.14 "{&pi}" 6.28 "2{&pi}" 9.42 "3{&pi}" 12.57 "4{&pi}") labeled the x axis with
    the numeric values given and substituted text for the numeric values; see [G-3]
    axis_label_options.

    plotregion(style(none)) suppressed the border around the plot region; see [G-3]
    region_options.

    xsca(noline) suppressed the drawing of the x-axis line; see [G-3] axis_scale_options.


Advanced use 1

    The following graph appears in many introductory textbooks:

        . twoway
              function y=normalden(x), range(-4 -1.96) color(gs12) recast(area)
          ||  function y=normalden(x), range(1.96 4)   color(gs12) recast(area)
          ||  function y=normalden(x), range(-4 4) lstyle(foreground)
          ||,
              plotregion(style(none))
              ysca(off) xsca(noline)
              legend(off)
              xlabel(-4 "-4 sd" -3 "-3 sd" -2 "-2 sd" -1 "-1 sd" 0 "mean"
                      1  "1 sd"  2  "2 sd"  3  "3 sd"  4  "4 sd"
                      , grid gmin gmax)
              xtitle("")
          (click to run)

    We drew the graph in three parts:  the shaded area on the left, the shaded area on the
    right, and then the overall function.  To obtain the shaded areas, we used the
    advanced_option recast(area) so that, rather than the function being plotted by graph twoway
    line, it was plotted by graph twoway area; see [G-3] advanced_options and [G-2] graph twoway
    area.  Concerning the overall function, we drew it last so that its darker
    foreground-colored line would not get covered up by the shaded areas.


Advanced use 2

    function plots may be overlaid with other twoway plots.  For instance, function is one way
    to add y=x lines to a plot:

        . sysuse sp500, clear

        . scatter open close, msize(*.25) mcolor(*.6) ||
          function y=x, range(close) yvarlab("y=x") clwidth(*1.5)
          (click to run)

    In the above, we specified the advanced_option yvarlab("y=x") so that the variable label of
    y would be treated as "y=x" in the construction of the legend; see [G-3] advanced_options.
    We specified msize(*.25) to make the marker symbols smaller, and we specified mcolor(*.6) to
    make them dimmer; see [G-4] relativesize and [G-4] colorstyle.




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-7-26 04:54:30
蓝色 发表于 2015-7-25 20:54
twoway function y=x+x^2+x^3, range(-50 50)
非常感谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-7-26 04:55:06
ywh19860616 发表于 2015-7-25 20:03
http://www.fight-entropy.com/2013/01/plot-polynomial-of-any-degree-in-stata.html
非常感谢!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-7-26 04:57:00
我也没看见楼主说的重谢是怎么兑现的,呵呵
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群