Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, 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: string variable |

Date |
Fri, 3 Aug 2012 09:07:29 -0500 |

Given access to Stata I can confirm 1. The FAQ that I referred to is FAQ . . . . . . . . . . . . . . . . . . . Ado-files and string comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox 4/01 Why does a program defined by an ado-file sometimes not work when given a string comparison? http://www.stata.com/support/faqs/programming/ ado-files-and-string-comparisons/ Note that -search string- in Stata would have pointed you to that FAQ. The Statalist FAQ advises looking at the Stata FAQ before posting, 2. -_gwtmean.ado- from SSC is written under -version 3.0- and so the problem explained in the FAQ above will certainly bite. Here is a demo of how easy it to get a weighted mean variable via -statsby- and -merge-: . sysuse auto, clear (1978 Automobile Data) . save auto2 file auto2.dta saved . statsby mean = r(mean) , by(rep78, missing) : su mpg [w=length] , meanonly (running summarize on estimation sample) command: summarize mpg [fweight= length], meanonly mean: r(mean) by: rep78 Statsby groups ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 ...... . merge 1:m rep78 using auto2 Result # of obs. ----------------------------------------- not matched 0 matched 74 (_merge==3) ----------------------------------------- Nick On Fri, Aug 3, 2012 at 3:36 AM, "Fabian Schönenberger" <sch.f@gmx.ch> wrote: > Many thanks Nick. > > -encode- worked fine. > > Fabian > > -------- Original-Nachricht -------- >> Datum: Fri, 3 Aug 2012 08:41:12 +0100 >> Von: Nick Cox <njcoxstata@gmail.com> >> An: "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> >> Betreff: Re: st: string variable > >> My guess is that -wtmean()- is written for some version of Stata -- >> say around Stata 5 -- sufficiently old that by an old misfeature it >> behaves as if the quotation marks were stripped on parsing. I wrote an >> FAQ on this about 10 or 12 years ago, but can't find it using only a >> phone. >> >> Your solutions include >> >> to rewrite -wtmean()- >> >> to -encode- your string variable and work with the corresponding >> numeric variable (this is probably closest to what else you are doing) >> >> to write a loop using -summarize- and -replace- >> >> to use -statsby-. >> >> Nick >> >> On 3 Aug 2012, at 06:14, "Fabian Schönenberger" <sch.f@gmx.ch> wrote: >> >> > Dear Statalist >> > >> > I try the following commands: >> > >> > . levelsof SIZEBM,local(levels) >> > `"BH"' `"BL"' `"BM"' `"SH"' `"SL"' `"SM"' >> > >> > foreach l of local levels { >> > egen meanwreturn_`l'=wtmean(trt1m) if SIZEBM=="`l'",weight(size) by >> > (datemt) >> > } >> > BH not found >> > r(111); >> > >> > wtmean is from SSC. >> > >> > SIZEBM is a string variable, generated with the command >> > >> > egen SIZEBM=concat(SIZE BM) >> > >> > It seems the problem is not the foreach, but the term - >> > SIZEBM=="`l'" - >> > >> > Any ideas the solve the problem highly appreciated. * * 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: string variable***From:*"Fabian Schönenberger" <sch.f@gmx.ch>

**Re: st: string variable***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: string variable***From:*"Fabian Schönenberger" <sch.f@gmx.ch>

- Prev by Date:
**RE: st: comparing coefficients across models** - Next by Date:
**RE: st: What is the effect of centering on marginal effects?** - Previous by thread:
**Re: st: string variable** - Next by thread:
**st: How to calculate confidence interval of the long-run elasticity** - Index(es):