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: question about local and var[n]
From 
 
Matthew White <[email protected]> 
To 
 
[email protected] 
Subject 
 
Re: st: question about local and var[n] 
Date 
 
Tue, 25 Oct 2011 02:25:25 -0400 
You probably want:
local city = ID[1]
not:
local city ID[1]
The latter just assigns the string "ID[1]" to `city'. -display
"`city'"- will display "ID[1]" not "ny". The former, on the other
hand, first evaluates the expression ID[1], THEN assigns the result to
`city'. ID[1] will evaluate to "ny", which is then assigned to `city'.
-display "`city'"- will display "ny".
Hope that helps!
Best,
Matt
On Tue, Oct 25, 2011 at 1:47 AM, G. Dai <[email protected]> wrote:
> Dear all,
> I have one question about the use of local macros.
> For example, assume the date
>
> ID     ny_price
> ny      5
> wa      4
>
> set obs 2
> gen str ID=""
> replace ID="ny" in 1
> replace ID="wa" in 2
> gen ny_price=4
> replace ny_price=5 in 1
>
>
> Then My question comes from the following differences:
>
>
> . local city ny
>
> .
> . replace `city'_price=100 in 1
> (1 real change made)
>
>
> However,
>
> . local city ID[1]
> . di `city'
> ny
> . replace `city'_price=100 in 1
> weights not allowed
> r(101);
>
> Why?
> thanks!
> *
> *   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/
>
-- 
Matthew White
Data Coordinator
Innovations for Poverty Action
101 Whitney Avenue, New Haven, CT 06510 USA
+1 434-305-9861
www.poverty-action.org
*
*   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/