Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #46
    Your original syntax was asking for

    regression lines and data points for each subset in front

    regression lines and data points for other subsets in back

    There are many variants on this. Here's one with extra twists to match the example. rangestat and mylabels are from SSC, as is fabplot.


    Code:
    webuse grunfeld, clear
    gen ln_invest = ln(invest)
    rangestat (reg) ln_invest year, int(company 0 0)
    gen predicted = b_cons + b_year * year
    label var predicted "predicted investment (linear fit on log scale)"
    mylabels 1 3 10 30 100 300 1000, myscale(ln(@)) local(yla)
    fabplot line predicted year, by(company) select(company <= 4) frontopts(lw(thick)) yla(`yla') xtitle("") xla(1935 " 1935" 1955 "1955 " 1940(5)1950, format(%tyYY))
    Click image for larger version

Name:	fabplot_regline.png
Views:	1
Size:	60.5 KB
ID:	1607135

    Last edited by Nick Cox; 02 May 2021, 01:06.

    Comment


    • #47
      Thanks to Kit Baum as ever, fabplot has been updated on SSC. The immediate prompt for updating was to fix a bug that I noticed (evidently before anyone else) but the help file has also been updated in various details.

      If fabplot is of interest, please update your version.

      Comment


      • #48
        A paper on this problem and the fabplot command is now published at https://www.stata-journal.com/articl...article=gr0087 and is accessible regardless of whether you or your workplace subscribe to the Journal.

        Comment


        • #49
          Have to say that the program is sooo fancy and efficient. One question about the issue of missing data: I found the subsetplot will only connect the non-missing observations, I'm wondering if there's any options for leaving the missing place as what it is, so that we may be able to get non-continuous lines.

          Comment


          • #50
            subsetplot from SSC (all versions 2014) is, in my view, superseded by fabplot (Stata Journal).

            EIther program ignores missing values, so as far as the final plot is concerned, there are no gaps with missing values to take account of.

            Here is some technique that may help. If you use connect for the front plot, the markers make clear where data are present.

            Code:
            webuse grunfeld, clear
            replace invest = . if year == 1944
            fabplot line invest year, by(company) ysc(log) front(connect) scheme(s1color)

            Comment

            Working...
            X