# st: Simulation: marginal effect at the 5th percentile Classic List Threaded 10 messages Reply | Threaded
Open this post in threaded view
|

## 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/
Reply | Threaded
Open this post in threaded view
|

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

 Line for the server... You must dereference your -local- in mfx, predict(p) at(mean a= `ap5' X2=0) On top of that, you do not want a -return scalar- for your r(p5) but a -local-: loc ap5 = r(p5) Also note a typo (exchange the curly for square bracket): ret scalar dydxmfxap5 = dydxmfx{1,1] HTH Martin -----Original Message----- From: [hidden email] [mailto:[hidden email]] 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/
Reply | Threaded
Open this post in threaded view
|

## Re: st: Simulation: marginal effect at the 5th percentile

 In reply to this post by Supnithadnaporn, Anupit --- "Supnithadnaporn, Anupit" <[hidden email]> wrote: > 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. Apart from the excellent comments by Martin, you can also use the fact that you do have a good idea what the percentile should be, as you created the variable to be normally distributed: local percentile = invnormal(.05) The advantage of this approach is that this way you can get away with creating smaller datasets, and thus speed up your simulation, because you now no longer need a large dataset to get a reliably/stable estimate of the percentile. Hope this helps, Maarten ----------------------------------------- Maarten L. Buis Department of Social Research Methodology Vrije Universiteit Amsterdam Boelelaan 1081 1081 HV Amsterdam The Netherlands visiting address: Buitenveldertselaan 3 (Metropolitan), room N515 +31 20 5986715 http://home.fsw.vu.nl/m.buis/-----------------------------------------       * *   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/
Reply | Threaded
Open this post in threaded view
|

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

 In reply to this post by Supnithadnaporn, Anupit 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: [hidden email] [mailto:[hidden email]] 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/
Reply | Threaded
Open this post in threaded view
|

## st: Extract confident intervals (ci) after regression

 Dear all I would like to extract an e()-class result stored in a matrix after regression.I would like to have the upper and lower bound of the ci but it doesn't work reg y x1 x2 matrix A=e(ci) svmat A, names(c Any tips Thank you Dejan * *   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/
Reply | Threaded
Open this post in threaded view
|

## st: RE: Extract confident intervals (ci) after regression

 Line for the server... Recommendation: http://www.stata-journal.com/article.html?article=st0137to understand the calculations necessary and  -ssc d parmest- to automate... HTH Martin -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Loncar, Dejan Sent: Tuesday, December 02, 2008 3:06 PM To: [hidden email] Subject: st: Extract confident intervals (ci) after regression Dear all I would like to extract an e()-class result stored in a matrix after regression.I would like to have the upper and lower bound of the ci but it doesn't work reg y x1 x2 matrix A=e(ci) svmat A, names(c Any tips Thank you Dejan * *   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/
Reply | Threaded
Open this post in threaded view
|

## st: RE: Extract confident intervals (ci) after regression

 In reply to this post by Loncar, Dejan Line for the server... BTW, Dejan: There is no -e(ci)- returned after -regress-. Type -eret li- immediately after -regress- to see that it hands back -e(b)- and -e(V)-. Upper and lower bounds are returned by commands such as -ci- which explicitly address confidence intervals ********** sysuse auto, clear ci len ret li ********** HTH Martin -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Loncar, Dejan Sent: Tuesday, December 02, 2008 3:06 PM To: [hidden email] Subject: st: Extract confident intervals (ci) after regression Dear all I would like to extract an e()-class result stored in a matrix after regression.I would like to have the upper and lower bound of the ci but it doesn't work reg y x1 x2 matrix A=e(ci) svmat A, names(c Any tips Thank you Dejan * *   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/
Reply | Threaded
Open this post in threaded view
|

## Re: st: Extract confident intervals (ci) after regression

 In reply to this post by Loncar, Dejan You didn't specify what you want the lower and upper limits of. Regardless, -regress- returns two matrices,   e(b) a coefficient vector and e(V) a variance-covariance matrix of the estimators.  I don't think there is an e(ci) matrix. You can make use of the stored estimates by doing something like this: local lbx1 = _b[x1] - invttail(e(df_r),0.025)*_se[x1] local ubx1 = _b[x1] + invttail(e(df_r),0.025)*_se[x1] local lbx2 = _b[x2] - invttail(e(df_r),0.025)*_se[x2] local ubx2 = _b[x2] + invttail(e(df_r),0.025)*_se[x2] local lb_cons = _b[_cons] - invttail(e(df_r),0.025)*_se[_cons] local ub_cons = _b[_cons] + invttail(e(df_r),0.025)*_se[_cons] di "X1 LL=`lbx1'    "     "UL="`lbx1' di "X1 LL=`lbx2'    "     "UL="`lbx2' di "B0 LL=`lb_cons' "     "UL="`ub_cons' Best, Alan On Tue, Dec 2, 2008 at 9:05 AM, Loncar, Dejan <[hidden email]> wrote: > Dear all > I would like to extract an e()-class result stored in > a matrix after regression.I would like to have the upper and lower > bound of the ci but it doesn't work > > reg y x1 x2 > matrix A=e(ci) > svmat A, names(c > > Any tips > > Thank you > Dejan > > * > *   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/
Reply | Threaded
Open this post in threaded view
|

## st: RE: RE: Extract confident intervals (ci) after regression

 In reply to this post by Martin Weiss-5 Thank you -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Martin Weiss Sent: 02 December 2008 15:22 To: [hidden email] Subject: st: RE: Extract confident intervals (ci) after regression Line for the server... BTW, Dejan: There is no -e(ci)- returned after -regress-. Type -eret li- immediately after -regress- to see that it hands back -e(b)- and -e(V)-. Upper and lower bounds are returned by commands such as -ci- which explicitly address confidence intervals ********** sysuse auto, clear ci len ret li ********** HTH Martin -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Loncar, Dejan Sent: Tuesday, December 02, 2008 3:06 PM To: [hidden email] Subject: st: Extract confident intervals (ci) after regression Dear all I would like to extract an e()-class result stored in a matrix after regression.I would like to have the upper and lower bound of the ci but it doesn't work reg y x1 x2 matrix A=e(ci) svmat A, names(c Any tips Thank you Dejan * *   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/* *   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/
Reply | Threaded
Open this post in threaded view
|

## RE: st: Extract confident intervals (ci) after regression

 In reply to this post by Alan Neustadtl Thank you Alan I was thinkoing about confident intervals (ci) after regression Thank you Dejan -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Alan Neustadtl Sent: 02 December 2008 15:33 To: [hidden email] Subject: Re: st: Extract confident intervals (ci) after regression You didn't specify what you want the lower and upper limits of. Regardless, -regress- returns two matrices,   e(b) a coefficient vector and e(V) a variance-covariance matrix of the estimators.  I don't think there is an e(ci) matrix. You can make use of the stored estimates by doing something like this: local lbx1 = _b[x1] - invttail(e(df_r),0.025)*_se[x1] local ubx1 = _b[x1] + invttail(e(df_r),0.025)*_se[x1] local lbx2 = _b[x2] - invttail(e(df_r),0.025)*_se[x2] local ubx2 = _b[x2] + invttail(e(df_r),0.025)*_se[x2] local lb_cons = _b[_cons] - invttail(e(df_r),0.025)*_se[_cons] local ub_cons = _b[_cons] + invttail(e(df_r),0.025)*_se[_cons] di "X1 LL=`lbx1'    "     "UL="`lbx1' di "X1 LL=`lbx2'    "     "UL="`lbx2' di "B0 LL=`lb_cons' "     "UL="`ub_cons' Best, Alan On Tue, Dec 2, 2008 at 9:05 AM, Loncar, Dejan <[hidden email]> wrote: > Dear all > I would like to extract an e()-class result stored in a matrix after > regression.I would like to have the upper and lower bound of the ci > but it doesn't work > > reg y x1 x2 > matrix A=e(ci) > svmat A, names(c > > Any tips > > Thank you > Dejan > > * > *   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/* *   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/