Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: local variable and indexing into a variable


From   "David E Moore" <[email protected]>
To   [email protected]
Subject   RE: st: RE: local variable and indexing into a variable
Date   Thu, 23 Jun 2005 17:52:05 -0700

What your example does is probably not what you want.  In particular, using
"[_n]" on the right-hand side really does nothing special.  You'd get the same
result if you left it off.

Perhaps at this point, you should explain what you're trying to do.  There may
be a very efficient way to accomplish it that isn't obvious.

-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of NEYMOTIN,
FLORENCE
Sent: Thursday, June 23, 2005 5:36 PM
To: [email protected]
Subject: Re: st: RE: local variable and indexing into a variable


thanks, that makes sense, but is there a general way to refer to the value
specifically?  The
reason I ask is because I have other statements that look like:  scalar
`var'_scalar=`var'[_n]
 that aren't as easy to replace in the way suggested.
thanks,
florence




On Thu, 23 Jun 2005 17:26:19 -0700
  "David E Moore" <[email protected]> wrote:
> Stata prefers:
>
> replace `var' = 0 if _n==_N
>
>
> -----Original Message-----
>From: [email protected]
> [mailto:[email protected]]On Behalf Of NEYMOTIN,
>FLORENCE
> Sent: Thursday, June 23, 2005 5:15 PM
> To: [email protected]
> Subject: st: local variable and indexing into a variable
>
>
> Hi, I tried typing:
>
> foreach var in x y {
> replace `var'[_N]=0
> }
>
> then it considers [_N] a "weight" when clearly I want it to just change the
last
> observation of
> both x and y to be zeroes.
>
> alternatively, I tried the inner line as: ( replace `var[_N]'=0 )    and then
it
> doesn't recognize
> var[_N] and thinks that it is an entirely new local reference.
> Is there a correct syntax here, or does it look like there is some other sort
of
> mistake in my
> coding ?
> thanks,
>Florence
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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