Announcement

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

  • Marginal effects after REPEST command

    Dear Statalist members! Iwould be most grateful for help. I am using PISA data for research project, with REPEST function for dealing with plausible values/weighting. And I need to get marginal effects. The problem is that REPEST and margins, dydx are not compatible. Help file for REPEST suggest writing a program. While it gives a good example how to predict margins, I struggle to get marginal effects which doesn't seem to work. I would be most grateful for any help! What I have tried so far is following:


    cap program drop myolsmargins
    program define myolsmargins, eclass
    syntax [if] [in] [pweight] , reg (string) [margins, dydx(string) moptions(string)]
    tempname b m
    // compute regression, store results in vectors
    reg `reg' `if' `in', `options'
    matrix `b'= e(b)
    // compute marginal effects, store results in vectors
    if "`margins`'" != "" | "`moptions'" != ""{
    margins, dydx `margins' post `moptions'
    matrix `m' = e(b)
    matrix colnames `m' = margins:
    matrix `b'= [`b', `m']
    }
    // post results
    ereturn post `b'
    end


    repest PISA, estimate(stata: version 14: myolsmargins, reg (pv@math i.misced##i.fisced wealth_z , vce (cluster schoolid)) margins, dydx(i.misced i.fisced) moptions(atmeans))


  • #2
    I should add, when I try to use this, I get the message : "option dydx not allowed"

    Comment


    • #3
      Hi Olga, did you ever resolve this issue? If so, I would deeply appreciate the solution you used. Thank you!

      Comment


      • #4
        I have not often used margins and never used repest or PISA data but there seem to be several bugs in that code.

        Code:
         
        cap program drop myolsmargins
        program define myolsmargins, eclass
        syntax [if] [in] [pweight] , reg(string) [margins(string) dydx(string) moptions(string) *]
        tempname b m
        // compute regression, store results in vectors
        reg `reg' `if' `in', `options'
        matrix `b'= e(b)
        // compute marginal effects, store results in vectors
        if "`margins`'" != "" | "`moptions'" != ""{
        margins, dydx(`dydx') `margins' post `moptions'
        matrix `m' = e(b)
        matrix colnames `m' = margins:
        matrix `b'= [`b', `m']
        }
        // post results
        ereturn post `b'
        end
        Warning, warning, warning: Some wild guesses. No testing. Zero accountability.

        Comment

        Working...
        X