Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

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

From |
Thomas Jacobs <thomasjacobs@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: Irritating if...else question for mata vs. stata |

Date |
Sun, 6 Jun 2010 21:41:36 -0500 |

Nick, Back again. Here is the type of behavior that led me to write in the first place. I have a do file calling another do to generate a Latex table. The latter do is part mata to aggregate variable values and then switches back to stata for the table generation portion. Here is how the final part of the mata code appears utilizing the belief that mata if blocks need not be followed by empty else blocks and the error it generates: : if (FirstCDXDay > 0) { > > CDXAdjSizePowVRight = vec(CountCDXAdjSizePowRight') > CDXMktSizePowVRight = vec(CountCDXMktSizePowRight') > CDXAdjSizePowVLeft = vec(CountCDXAdjSizePowLeft') > CDXMktSizePowVLeft = vec(CountCDXMktSizePowLeft') > > } > > end unexpected end of line (117 lines skipped) Now, I add back the heretofore extraneous else block and the program continues on to successful completion: : if (FirstCDXDay > 0) { > > CDXAdjSizePowVRight = vec(CountCDXAdjSizePowRight') > CDXMktSizePowVRight = vec(CountCDXMktSizePowRight') > CDXAdjSizePowVLeft = vec(CountCDXAdjSizePowLeft') > CDXMktSizePowVLeft = vec(CountCDXMktSizePowLeft') > > } > else{ > } : : end ---------------------------------------------------------------------------------------------- . . if ${BootstrapSwitch} file open tex using table_SizePow_${ObsLength}Obs_${EventLength}DayEv_ > ${Ret}Diffs_${MCtrials}MCtrials_${Bootstraps}Bootstraps${Grade}Indexes.tex, write replace .... remainder of program cut off for readability. Any suggestions for what I may be missing or how I might better understand what is going on here? The programs are long so I don't wish to post them, but certainly there must be some explanation for such behavior. It has happened to me before and I make a habit of posting empty else blocks all over the place and thus, led me to the mata manual with its ambiguous definitions and finally to post here. Thanks, Tom On Sun, Jun 6, 2010 at 1:31 PM, Thomas Jacobs <thomasjacobs@gmail.com> wrote: > Nick, > > Thanks very much, you basically carried out the experiment Martin had > directed me to. > > I am pretty much grasping at straws at this point on this overly > lengthy and convoluted program for which I lack the time to rewrite > before my delivery deadline. > > Thanks again, > > Tom > > On Sun, Jun 6, 2010 at 1:27 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote: >> You need not apologise that (you think) your question is irritating. >> >> No -else- is needed in Mata with multiple blocks. >> >> Here's a dopey demo to run. >> >> mata : >> >> void testif() { >> if (42 > 0) { >> "42 is positive" >> "Scotland is wet" >> "Bears don't behave nicely in the woods" >> } >> } >> >> testif() >> >> end >> >> Nick >> n.j.cox@durham.ac.uk >> >> Thomas Jacobs >> >> I am trying to determine whether an if block is acceptable in mata >> without an else block even if else is empty. >> >> In the Stata manual for if it specifically shows the following - I am >> ignoring the single line if statement command: >> >> if exp { >> >> multiple commands >> >> } >> >> which...MAY be followed by else etc. >> >> However in the mata manual only the single line line if(exp) sttmnt 1 >> is displayed. All the other examples have a trailing else whether in >> block or single line form. In the description, however, it states "if >> evaluates the expression, and if it is true, if executes the statement >> or statement block that immediately follows it; otherwise, if skips >> the statement or block." >> >> I interpret the latter description to be that one can use the if block >> without a trailing else. >> >> The lack of precision is frustrating, however, and I am struggling to >> interpret odd program behavior. Can anyone definitively state whether >> the following is proper programming form for mata: >> >> if (exp) { >> >> multiple statements >> >> } >> >> with no trailing empty >> >> else{ >> } >> >> ? Thanks. >> >> >> * >> * 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/ >> > > > > -- > Thomas Jacobs > -- Thomas Jacobs * * 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/

**Follow-Ups**:**RE: st: RE: Irritating if...else question for mata vs. stata***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**st: Irritating if...else question for mata vs. stata***From:*Thomas Jacobs <thomasjacobs@gmail.com>

**st: RE: Irritating if...else question for mata vs. stata***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: RE: Irritating if...else question for mata vs. stata***From:*Thomas Jacobs <thomasjacobs@gmail.com>

- Prev by Date:
**Re: st: R: Propensity score matching** - Next by Date:
**Re: st: -ssc new- error** - Previous by thread:
**Re: st: RE: Irritating if...else question for mata vs. stata** - Next by thread:
**RE: st: RE: Irritating if...else question for mata vs. stata** - Index(es):