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: About - local macname: list posof "element" in A -
From
Kieran McCaul <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: About - local macname: list posof "element" in A -
Date
Mon, 3 Feb 2014 10:07:23 +0800
...
So do I.
So the script you have posted is not the script you are running.
If it is, type -update query- to see if you are running the most up-to-date version of Stata.
If the problem remains, type the following above the -foreach- step and re-run the script.
set trace on
set trace depth 1
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Monday, 3 February 2014 8:19 AM
To: [email protected]
Subject: Re: st: About - local macname: list posof "element" in A -
I can't reproduce this. I get 1 2 3 ... 27 for the positions as one
would expect.
Nick
[email protected]
On 2 February 2014 13:46, Dimitri Silva <[email protected]> wrote:
> Dear Statalist,
>
> I attemped to use the command 'local macname: list posof "element" in A' and
> I had problems. I have two lists to define as local macros: one will be used
> as a list of values (ufvalues) and the other as a list of names (ufsiglas).
> There is something wrong with my code (and I can't figure it out what it is)
> in that Stata does not find the position of the first value of my macro
> ufvalues (as it says that its position is 0).
>
> Here's the code I wrote:
>
> gen byte uf = .
> local ufsiglas AC AL AM AP BA CE DF ES GO MA MG MS MT PA PB PE PI PR RJ RN
> RO RR RS SC SE SP TO
> local ufvalues 12 27 13 16 29 23 53 32 52 21 31 50 51 15 25 26 22 41 33 24
> 11 14 43 42 28 35 17
>
> foreach ufvalue in `ufvalues' {
> local posofufval : list posof "`ufvalue'" in ufvalues
> display "(`posofufval', `ufvalue')"
> * replace uf = `ufvalue' if sigla_uf == "`: word `posofufval' in
> `ufsiglas''"
> * local lbuf `lbuf' `ufvalue' `"`: word `posofufval' in `ufsiglas''"'
> }
>
> I asked Stata to run the line display "(`posofufval', `ufvalue')" in order
> two see what was wrong, and I got this:
>
> (0, 12)
> (2, 27)
> (3, 13)
> (4, 16)
> (5, 29)
> (6, 23)
> (7, 53)
> (8, 32)
> (9, 52)
> (10, 21)
> (11, 31)
> (12, 50)
> (13, 51)
> (14, 15)
> (15, 25)
> (16, 26)
> (17, 22)
> (18, 41)
> (19, 33)
> (20, 24)
> (21, 11)
> (22, 14)
> (23, 43)
> (24, 42)
> (25, 28)
> (26, 35)
> (27, 17)
>
> It seems that value 12 is not found in ufvalues! Can anyone explain to me
> what is wrong with my code?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/