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]
Re: st: e(wexp) versus e(wexp): different routines return different things
From
Stas Kolenikov <[email protected]>
To
[email protected]
Subject
Re: st: e(wexp) versus e(wexp): different routines return different things
Date
Sat, 27 Aug 2011 16:51:41 -0500
Nick,
the original poster had an issue of some commands returning -e(wexp)-
with an equal sign, and others, without it. So the equal sign had to
be parsed out.
On Sat, Aug 27, 2011 at 2:44 PM, Nick Cox <[email protected]> wrote:
> 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 <[email protected]> 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
>> <[email protected]> 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/
>
--
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/