Bookmark and Share

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]

st: About - local macname: list posof "element" in A -


From   Dimitri Silva <[email protected]>
To   "Statalist" <[email protected]>
Subject   st: About - local macname: list posof "element" in A -
Date   Sun, 2 Feb 2014 11:46:45 -0200

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?

Thanks a lot for any help.

Dimitri.
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index