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

st: AW: Using svy with by

From   "Martin Weiss" <>
To   <>
Subject   st: AW: Using svy with by
Date   Tue, 4 Aug 2009 13:16:48 +0200


Apart from other problems, you are treating -mean- as if it was a function.
You have to -generate- the mean estimate first, and then do the -replace-

Note the difference:

sysuse auto, clear
by f: gen mean=mean(pr)

sysuse auto, clear
gen meanpr=.
levelsof for, loc(myfor)

foreach lev in `myfor'{
	su pr if for==`lev', mean
	replace meanpr=`r(mean)' if for==`lev'


-----Ursprüngliche Nachricht-----
[] Im Auftrag von
Gesendet: Dienstag, 4. August 2009 12:14
Betreff: st: Using svy with by

Hi all,
I'm trying to find a way around a problem. The code below results in an
error since svy cannot by combined with by. I cannot think of another way to
get the equivalent result I need, however, since the mean I'm attempting to
calculate must be run using svy.
Any ideas?

foreach varname of varlist `PAYMENTVARS' {
generate `varname'PANAVG = 0
  by DUPERSID PURCHRD, sort: svy: replace `varname'PANAVG = mean(`varname')
  by DUPERSID PURCHRD: keep if _n==_N
  drop `varname'

svy may not be combined with by




Please access the attached hyperlink for an important electronic
communications disclaimer:

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index