Bookmark and Share

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]

Re: st: Weights now allowed


From   Ulrich Kohler <kohler@wzb.eu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Weights now allowed
Date   Thu, 13 Sep 2012 21:10:53 +0200

BTW the reason why

. replace ravgexpretage[`i'] = r1expretage[`i'] + r3expretage[`i'] ... 

didn't work is the pair of brackets in front of the equal sign. The
commands -generate- and -replace- expects a variable name after the
command and "ravgexpretage[`i']" is not a valid variable name. Stata
therefore interprets all that is inside [] as a weight and claims that
weights are not allowed with -replace. 

Note that -generate-/-replace- expect an "expression" behind the equal
sign and "r1expretage[`i']" is valid syntax for an expression. 

If you would realy need to do want you wanted to do the code would have
been 

. sysuse auto
. gen myvar = .
. forv i = 1/10 {
.	replace myvar = mpg[`i'] in `i'
. }

But you should never do something like that with Stata!

Uli




Am Donnerstag, den 13.09.2012, 14:24 -0400 schrieb Daniel Almar de
Sneijder:
> wow its a miracle, it actually works
> 
> thanx
> 
> i'll still go for tiger :)
> 
> On Thu, Sep 13, 2012 at 2:16 PM, Scholes, Shaun <s.scholes@ucl.ac.uk> wrote:
> > Are you sure? Try:
> >
> > clear
> > input x1 x2 x3
> > . 1 2
> > 2 2 3
> > 4 . .
> > end
> >
> > egen tiger = rowmean(x1-x3)
> > list tiger
> >
> > Sorry, I am a golf fan. Maybe that should be -egen Rory-.
> > best wishes
> > Shaun
> >
> >
> >
> >
> > -----Original Message-----
> > From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Daniel Almar de Sneijder
> > Sent: 13 September 2012 19:05
> > To: statalist@hsphsun2.harvard.edu
> > Subject: Re: st: Weights now allowed
> >
> > Hello and thanks for the message.
> >
> > The reason I loop over the data is because sometimes only 3 variables have an observation.
> > When I use rowmean then it treats the outcome as 0 if at that row not all observations have a value. So to clarify, I want to obtain the average in this way:
> >
> > x1 x2 x3     avg(x1 x2 x3)
> > .   1   2             1.5
> > 2  2   3              7/3
> > 4 . .                   4
> >
> >
> >
> >
> >
> >
> > I tried it btw now with 'i' but it still doesnt work???
> >
> >
> > ***** calculates average expretage
> > drop ravgexpretage
> > gen double ravgexpretage = r1expretage
> > forvalues i = 1/30659 {
> > replace ravgexpretage[`i'] = (r1expretage[`i'] + r3expretage[`i'] + r4expretage[`i'] + r5expretage[`i'] + r6expretage[`i'] + r7expretage[`i'] + r8expretage[`i'])/7 }
> > ******
> >
> >
> >
> >
> > On Thu, Sep 13, 2012 at 1:50 PM, Joerg Luedicke <joerg.luedicke@gmail.com> wrote:
> >> You would need to type [`i'] instead of [i] since i is a local macro
> >> here (see -help macro- and -help forvalues-). However, there is no
> >> need to loop over all observations in your data, see -help egen
> >> rowmean-.
> >>
> >> J.
> >>
> >> On Thu, Sep 13, 2012 at 12:23 PM, Daniel Almar de Sneijder
> >> <dasneijder@gmail.com> wrote:
> >>> Hello Stata
> >>>
> >>> When I attempt to run:
> >>>
> >>> ***** calculates average exp ret age
> >>> drop ravgexpretage
> >>>
> >>> gen double ravgexpretage = r1expretage
> >>>
> >>> forvalues i = 1/30659 {
> >>>   replace ravgexpretage[i] = ( r1expretage[i] + r3expretage[i] +
> >>> r4expretage[i] + r5expretage[i] + r6expretage[i] + r7expretage[i] +
> >>> r8expretage[i] )
> >>>   replace ravgexpretage[i] =  ravgexpretage[i] *(1/7) }
> >>>
> >>> I receive the message: "weights not allowed"
> >>>
> >>> What is the problem and How can I circumvene this?
> >>> My initial idea was to add all the variables up and then divide it by
> >>> 7, which works. However it only adds the observations up if each
> >>> variable has a observation So that is why I decided to do it like
> >>> this.
> >>>
> >>> Thanks,
> >>> Daniel
> >>> *
> >>> *   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/
> > *
> > *   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/
> *
> *   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index