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))
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))
Comment