Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: expanding numlist


From   "Radu Ban" <[email protected]>
To   [email protected]
Subject   st: expanding numlist
Date   Mon, 2 Jul 2007 10:45:01 -0400

Dear listers,

I have two variables: groupid and list. "groupid" identifies the group
and "list" is numeric list of members. For example:

groupid list
1          3 8 9 10
2         5/9 11 23/27
3         6 7/10
...       ...

Now "list" is always a valid numlist (because I entered it as such). I
want to get this data into a long format (i.e. expand "list" for each
"groupid"). But I'm having troubles from the start, I can't even get
Stata to read in each observation of "list" as a numlist. For example
I tried the following piece of code.

count
local end = r(N)
forvalues i=1/`end' {
local numbers "list[`i']"
foreach n of numlist `numbers' {
 di `n' /*just to test if this works*/
}
}

this gives me an error: invalid numlist

Setting the trace on, I see that
foreach n of numlist `numbers' { is processed as
foreach n of numlist list[1] { which is clearly an invalid -numlist-

However, when I try this:

count
local end = r(N)
forvalues i=1/`end' {
local numbers "list[`i']"
di `numbers'
}

I get a list of all the observations in "list", so `numbers' is being
read as the content of list[`i']. So I am puzzled why `numbers' cannot
be read as a -numlist-

So my direct question is how to read in "list" as numeric list. I
think once I do this I can manage to do my reshape.

Thanks,
Radu
*
*   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