Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Simulation: marginal effect at the 5th percentile


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Simulation: marginal effect at the 5th percentile
Date   Tue, 2 Dec 2008 10:54:18 +0100

Line for the server...

Here is an improved version of your -prog- (not an endorsement of your research strategy...). Crucially, the "X" in e(Xmfx_dydx) must be capitalized...

***********
cap prog drop simnorm

prog simnorm, rclass
  vers 9.0
  *construct data
  drop _all
  set obs 1000
  g X2=uniform()*3
  g X3=uniform()*0.5+2
  g Y=uniform()>0.7
  
	gen a = 3*invnorm(uniform())+ 5 //so mean 5, sd 3
	_pctile a, p(5)
	loc p5 = r(r1)
  logit Y a X2 X3, robust
  mfx, predict(p) at(mean a=`p5)' X2=0)
	mat dydxmfx = e(Xmfx_dydx)
	ret sca dydxmfxap5 = dydxmfx[1,1]
end

simulate dydxmfxap5 = r(dydxmfxap5), reps(100) : simnorm
*saving("C:\data\sima.dta", replace)
***********

HTH
Martin


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Supnithadnaporn, Anupit
Sent: Tuesday, December 02, 2008 5:19 AM
To: statalist
Subject: st: Simulation: marginal effect at the 5th percentile

Dear all,

I am running a simulation of the logit model. Each repetition I create a variable called 
"a", which is normally distributed. I would like to find the marginal effect of this 
variable at the certain percentiles of its distribution. The problem is that I cannot 
specify the number of the particular percentile in  -mfx, predict(p) at( )- 
because I don't know the value in each repetition. So I use the -r( )- from -sum-.
However,my program gives me the error from -mfx- part saying that

'indp5' found where number expected
an error occurred when simulate executed simlognorm

Is there a way to specify the unknown value in -at( )- of -mfx-? Would anybody please help? 

Thank you 
Anupit

----------------------------------------------------------
program define simnorm, rclass
        version 9.0
	gen a = sdX1*invnorm(uniform())+ meanX1
	sum a, detail
	   ret scalar ap5 = r(p5)
        logit Y a X2 X3, robust
        mfx, predict(p) at(mean a=ap5 X2=0)
	   mat dydxmfx = e(xmfx_dydx)
	   ret scalar dydxmfxap5 = dydxmfx{1,1]
	eret clear
	drop a
end

simulate dydxmfxap5 = r(dydxmfxap5), reps(100) saving("C:\data\sima.dta", replace): simnorm
----------------------------------------------------------



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index