Announcement

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

  • Margins, Non-parametric Regression

    Hi all,

    My code looks like this:
    "npregress kernel test01 test00
    npgraph
    margins
    marginsplot"

    Basically, I want to have a graph of given an x in test00, what is the predicted test01. My professor told me I should do this using margins. However, when I do margins and marginsplot, I only get one point and I think I need a point for many values. Specifically, my professor told me to break test00 in to ten different bins for some scores (1-2, 2-3, 3-4.....) and then predict based on these. Can someone help? I have tried playing around with different things on the margins command but I am getting nowhere.
    I want a graph that shows if you have a test00 in between 1-2, your predicted test01 is......and shows this for all the bins I create.
    Thank you!
    Best,
    Lindsey

  • #2
    Hi Lindsey,
    To get the plots that you want you need a code like the one below
    Code:
    clear all
    webuse dui, clear
    npregress kernel citations fines,
    margins, at(fines=(8(.5)12)) vce(bootstrap)
    marginsplot, name(g1) title(npreg)
    Alternatively, you can do something like this too:


    Code:
    gen qfines=ceil(fines/.5)*5
    reg citations i.qfines
    margins,over(qfines)
    marginsplot, name(g2) title(Dummies)
    
    graph combine g1 g2

    HTH

    Comment


    • #3
      Thank you so much!!

      Comment


      • #4
        I am now attempting to bootstrap it so I can get a an actual confidence interval:


        "/* beginning of Bootstrap loop */
        global numberBSreps=100
        forvalues i = 1/$numberBSreps {


        preserve
        bsample
        drop if treat==0
        drop if test00<-1.3
        drop if test00>1.6
        npregress kernel test00 test01
        margins, at (test00=(-1.3(.3)1.6))
        marginsplot, name(Treatment) title(Treatment Group)
        restore

        /* now we're done, go do another BS step */"

        Do you know what I am doing wrong? I want a graph that shows the confidence interval as well from bootstrapping!

        Comment


        • #5
          Lindsey: It looks to me like you don't want to do a smoothed kernel regression but rather a bin regression. Is that correct? This may seem clunky, but the way I would do that, and get standard errors for the change in the mean of test01 for different bin levels, is the following. I assume there are K total bins.

          reg test01 bin1 bin2 bin3 ... binK, nocons vce(robust)
          lincom b2 - b1
          lincom b3 - b2
          ...
          lincom bK - bK_1

          These will give the "marginal" effects along with standard errors and confident intervals.

          Comment

          Working...
          X