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 |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: e(wexp) versus e(wexp): different routines return different things |

Date |
Sat, 27 Aug 2011 20:44:42 +0100 |

Too complicated :) tempvar wvar if "`e(wexp)'" == "" generate byte `wvar' = 1 else generate double `wvar' `e(wexp)' On Sat, Aug 27, 2011 at 8:28 PM, Stas Kolenikov <skolenik@gmail.com> wrote: > Oh those overqualified programmers working in Stata :). Regular > expressions are an overkill for situation like this. You can achieve > what you need with the string functions. > > tempvar wvar > if "`e(wexp)'" == "" generate byte `wvar' = 1 > else { > local mywexp = subsinstr("`e(wexp)'","=","",1) > generate double `wvar' = `mywexp' > } > > and then you can pass `wvar'. > > On Fri, Aug 26, 2011 at 8:49 PM, Rodini, Mark > <mrodini@compasslexecon.com> wrote: >> Greetings, >> >> I have a program which executes after I run an estimation procedure, and it does a collapse where weighting is an option. >> Within the program is the following line: >> >> >> if "`e(wexp)'" != "" { >> collapse (mean) `y_sample' `xb_sample' [fw `e(wexp)'] >> } >> >> I'm running an estimation using "reg" and one using "newey2". Suppose the name of the weighting variable, should I opt to use it, is "mycount" so for example, I run: >> >> reg y high low cows [aw=mycount] >> >> and then execute the program. >> >> >> Both estimation routines create as output an estimation "variable" called e(wexp). Note that this is what is passed to the program as indicated above. >> >> Here is the kicker: reg returns e(wexp) as "= mycount", but newey2 returns e(wexp) as "mycount" (without the equals sign!) >> >> The reg version properly executes the program above, but newey2 gives an error about an inability to weight, since the syntax requires an equals sign. >> >> I have tried within the program to create a tempname or tempvar, assign e(wexp) to it and then tried running >> >> scalar `wts'=regexr(`e(wexp)',"=","") >> >> I then replace the `e(wexp)' in the program with `wts' and add an equals sign explicitly in the program. The idea I was hoping for is that it would replace the "=" with nothing in the macro variable, if one were there. >> >> No matter how I try it, it fails, usually with a type mismatch error. I tried adding double quotes, etc. I am assuming that because I'm trying to pass it as a scalar, that is what bombs it. Any thoughts? I'm guessing it's something pretty basic --I'm kind of new to writing complicated programs which pass lots of stuff. > > > > -- > Stas Kolenikov, also found at http://stas.kolenikov.name > Small print: I use this email account for mailing lists only. > > * > * 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/

**Follow-Ups**:**Re: st: e(wexp) versus e(wexp): different routines return different things***From:*Stas Kolenikov <skolenik@gmail.com>

**References**:**st: e(wexp) versus e(wexp): different routines return different things***From:*"Rodini, Mark" <mrodini@compasslexecon.com>

**Re: st: e(wexp) versus e(wexp): different routines return different things***From:*Stas Kolenikov <skolenik@gmail.com>

- Prev by Date:
**Re: st: store error term from individual panel regressions** - Next by Date:
**Re: st: regexm** - Previous by thread:
**Re: st: e(wexp) versus e(wexp): different routines return different things** - Next by thread:
**Re: st: e(wexp) versus e(wexp): different routines return different things** - Index(es):