【问题标题】:Line of best fit of marginsplot边距图的最佳拟合线
【发布时间】:2018-03-01 23:21:42
【问题描述】:

我正在尝试创建一个边距图并为那些绘制的边际值添加一条最适合的线以显示趋势,因为边距是在年份虚拟变量上绘制的。可以在此处看到 marginsplot,其中红线显示了我希望获得的结果(但只是我绘制的估计线):https://imgur.com/a/Uh2Q5

我的数据快照(仅限于与这篇文章相关的变量)可以在这里看到:https://imgur.com/a/FqsWm

任何关于如何在 marginsplot 上实现这条拟合线的建议将不胜感激!

谢谢

【问题讨论】:

    标签: graph regression stata margins


    【解决方案1】:

    目前尚不清楚您要绘制什么样的边距以及底层模型是什么,但这里有一些代码可以帮助您入门:

    sysuse auto, clear
    reg price i.rep78 c.weight
    eststo margins: margins rep78, post
    // eststo margins: margins, dydx(rep78) post
    
    /* store margins output as a variable */
    local levels: colnames e(b)
    gen margins = .
    foreach j of local levels  {
        replace margins = _b[`j'] if `j'==1
    }
    
    /* run a regression on the output of margins */
    reg margins c.rep78
    eststo lfit: margins, over(rep78) post
    
    /* plot both margins and linear approximation */
    coefplot (margins) (lfit, recast(line) offset(0)), vertical xlabel(, alternate)
    
    drop margins
    

    这会产生:

    coefplot 来自 SSC。


    以下是cmets中问题的解决方案:

    sysuse auto, clear
    reg price c.mpg##i.rep78 c.weight
    margins r.rep78, dydx(mpg) post
    /* store interaction coefficients as a variable */
    local levels: colnames e(b)
    gen margins = .
    foreach j of local levels  {
        replace margins = _b[`j'] if `j'==1
    }
    /* plot margins with added line */
    marginsplot, addplot(lfit margins rep78) recast(scatter) legend(off)
    

    【讨论】:

    • 抱歉没有发布我的模型!我以为我有,那是我的错误。 reg lgross c.lmovielikes##i.release_year lcastlikes lbudget imdb_score i.content_rating i.is_* ,稳健 我正在寻找绘制 c.movi​​elikes#i.release_year 的边距或系数,并用一条适合这些值的线覆盖在同一轴。
    • @ctahim 见上面的附录。
    猜你喜欢
    • 1970-01-01
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多