Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Mohamud Hussein <Mohamud.Hussein@fera.gsi.gov.uk> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: Optimize |

Date |
Tue, 24 Jul 2012 12:23:41 +0100 |

Thanks Yuval. I see the problem. Based on my interpretation of your advice, I re-specified the MC function as y= 3*x^2+2*x+1, where y=output (i.e. total number of samples tested under a certain analytical protocol) and x= per unit cost for each protocol. Is this specification endogeneity free? Thanks, Mohamud -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Yuval Arbel Sent: 23 July 2012 22:23 To: statalist@hsphsun2.harvard.edu Subject: Re: st: Optimize Since I saw Muhammad is an Economist, I have one conceptual remark: Note, that both the total cost (TC) and output (X) are endogenous variables in the classical economics model of producer behavior. Consequently, MC should be derived as a function of output and input prices per unit, and not of quantities (otherwise the simultaneous relations produces biased and inconsistent estimators). On Mon, Jul 23, 2012 at 9:52 PM, Austin Nichols <austinnichols@gmail.com> wrote: > Matthew Baker <matthew.baker@hunter.cuny.edu>: > That code minimizes the first derivative, according to the OP. I think > the OP wants to find the minimum of the cubic given, which means > setting the quadratic to zero in the case of an interior solution > (i.e. just use the quadratic formula, not Mata). But there are no > interior solutions for a cubic with positive coefs, so the OP needs to > substitute in any constraints holding with equality. Or perhaps I am > misunderstanding the desideratum here. > > On Mon, Jul 23, 2012 at 2:30 PM, Matthew Baker > <matthew.baker@hunter.cuny.edu> wrote: >> Mohamud -- >> >> I think there are a few things wrong with the code that you presented >> below. For one, I think you want the arguments of your void function >> to be (todo,x,crit,g,H) - otherwise, as written, you are not returning >> anything to the evaluator! Moreover, your objective function omits a >> few operators so I think it should be (3*x^2+2*x+1)^2. >> >> Given those few changes, a simplified version of your code that might >> get closer to what you want is something like: >> >> /* begin example */ >> clear all >> mata: >> void q(todo,x,crit,g,H) >> { >> crit=(3*x^2+2*x+1)^2 >> } >> real matrix grid(n1,n2) >> { >> real matrix sol >> real scalar i,p >> sol=J(0,2,0) >> for (i=n1; i<=n2; i++) { >> init=i >> S=optimize_init() >> optimize_init_evaluator(S, &q()) >> optimize_init_which(S,"min") >> optimize_init_evaluatortype(S,"d0") >> optimize_init_params(S,init) >> p=round(optimize(S),10e-8) >> sol=sol \ (i,p) >> } >> return(sol) >> } >> grid(-10,10) >> end >> /* end example */ >> >> Hope that helps! >> >> Matt Baker >> >> >> On Mon, Jul 23, 2012 at 11:45 AM, Mohamud Hussein >> <Mohamud.Hussein@fera.gsi.gov.uk> wrote: >>> Thanks Austin. >>> >>> I used code below as suggested but had no luck yet. I am sure it has something to do with my complete lack of knowledge in mata language. >>> >>> I attach my data. I would be grateful if you can check for me where I am getting it wrong. >>> >>> Many thanks, >>> Mohamud >>> >>> == >>> >>> void q(todo,x,y,g,H) >>> { >>> crit=(3x^2+2x+1)^2 >>> } >>> sol=J(1,0,0) >>> void grid(n1,n2) >>> { >>> external sol, p >>> for (i=n1; i<=n2; i++) { >>> init=i >>> S=optimize_init() >>> optimize_init_evaluator(S, &q()) >>> optimize_init_which(S,"min") >>> optimize_init_evaluatortype(S,"d0") >>> optimize_init_params(S,init) >>> p=round(optimize(S),10e-4) >>> if (!anyof(sol, p)) { >>> sol=(sol,p) >>> } >>> } >>> sol >>> } >>> grid(-10,10) >>> >>> == >>> >>> >>> -----Original Message----- >>> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Austin Nichols >>> Sent: 23 July 2012 15:26 >>> To: statalist@hsphsun2.harvard.edu >>> Subject: Re: st: Optimize >>> >>> Mohamud Hussein <Mohamud.Hussein@fera.gsi.gov.uk>: >>> Looks like you are trying to maximize the unbounded quadratic rather >>> than find its zeros. Use a root finder instead e.g. >>> http://www.stata.com/statalist/archive/2007-12/msg00551.html >>> http://www.stata.com/statalist/archive/2009-01/msg01140.html >>> but note first that the particular example you gave has no zeros (so >>> no interior solution). >>> >>> On Sun, Jul 22, 2012 at 9:59 AM, Mohamud Hussein >>> <Mohamud.Hussein@fera.gsi.gov.uk> wrote: >>>> Hi there, >>>> >>>> I am trying to run a model for a marginal cost curve equation based on the traditional cubic total cost curve function (i.e. y= x^3+X^2+X+c) using Stata's optimize() command. The goal is to estimate the value of x which minimises y subject to a number of constraints. >>>> >>>> When I tried to specify the marginal cost curve function in mata directly as y=3x^2+2x+1 (i.e. first derivative of the total cost equation) I got the following message: >>>> >>>> Iteration 0: f(p) = 1 (not concave) >>>> Iteration 1: f(p) = 7.911e+71 (not concave) >>>> Iteration 2: f(p) = 1.95e+169 (not concave) >>>> Iteration 3: f(p) = 8.32e+250 (not concave) >>>> Iteration 4: f(p) = 1.62e+288 (not concave) >>>> Iteration 5: f(p) = 2.34e+306 >>>> Hessian is not negative semidefinite >>>> >>>> I have never used Stata's mata programming language before and am not quite sure of what do here? Grateful if someone can help me on this. >>>> >>>> Thanks, >>>> Mohamud >>> >>> * >>> * 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/ >>> >>> The information contained in this message may include privileged, proprietary or confidential information. Please treat it with the same respect that you would expect for your own information. If you have received it in error, we apologise and ask that you contact the sender immediately and erase it from your computer. Thank you for your co-operation. >>> >>> The original of this email was scanned for viruses by the Government Secure Intranet virus scanning service. On leaving the GSi this email was certified virus free. >> > > * > * 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/ -- Dr. Yuval Arbel School of Business Carmel Academic Center 4 Shaar Palmer Street, Haifa 33031, Israel e-mail1: yuval.arbel@carmel.ac.il e-mail2: yuval.arbel@gmail.com * * 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/ The information contained in this message may include privileged, proprietary or confidential information. Please treat it with the same respect that you would expect for your own information. If you have received it in error, we apologise and ask that you contact the sender immediately and erase it from your computer. Thank you for your co-operation. The original of this email was scanned for viruses by the Government Secure Intranet virus scanning service. On leaving the GSi this email was certified virus free. * * 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/

**References**:**st: Optimize***From:*Mohamud Hussein <Mohamud.Hussein@fera.gsi.gov.uk>

**Re: st: Optimize***From:*Austin Nichols <austinnichols@gmail.com>

**RE: st: Optimize***From:*Mohamud Hussein <Mohamud.Hussein@fera.gsi.gov.uk>

**Re: st: Optimize***From:*Matthew Baker <matthew.baker@hunter.cuny.edu>

**Re: st: Optimize***From:*Austin Nichols <austinnichols@gmail.com>

**Re: st: Optimize***From:*Yuval Arbel <yuval.arbel@gmail.com>

- Prev by Date:
**Re: st: Propensity score matching in stata** - Next by Date:
**Re: st: suest mlogit equation not found error** - Previous by thread:
**Re: st: Optimize** - Next by thread:
**RE: st: Optimize** - Index(es):