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]

Re: st: RE: extract rownames corresponding to data as unique codes


From   Judy You <[email protected]>
To   [email protected]
Subject   Re: st: RE: extract rownames corresponding to data as unique codes
Date   Thu, 4 Aug 2011 09:06:44 +0930

ok, i see.

here is the log file with commands and results.

Thanks for your attention again!

Cheers

Judy


. use data, clear

. destring sla,replace
sla has all characters numeric; replaced as int

. qui dstdize deaths pop sex agegp, by(sla) using (t0)

. drop _all

. return list

scalars:
                 r(k) =  95

macros:
                r(by) : "sla"
               r(c95) : "`"5050"'"
               r(c94) : "`"5000"'"
------
                r(c4) : "`"207"'"
                r(c3) : "`"205"'"
                r(c2) : "`"203"'"
                r(c1) : "`"201"'"

matrices:
                r(se) :  1 x 95
                r(ub) :  1 x 95
                r(lb) :  1 x 95
               r(adj) :  1 x 95
             r(crude) :  1 x 95
              r(Nobs) :  1 x 95

. matrix C = r(crude)', r(adj)', r(lb)' , r(ub)'

. svmat C, names(col)
number of observations will be reset to 95
Press any key to continue, or Break to abort
obs was 0, now 95

.
. gen rowname = .
(95 missing values generated)

. qui forval i = 1/95 {
type mismatch
r(109);

end of do-file

r(109);




2011/8/3 Nick Cox <[email protected]>:
> Sorry, Judy, but this is not what was asked for. To understand an error
> message, it helps to see the code, meaning Stata commands, that was typed.
>
> Nick
>
> On 3 Aug 2011, at 01:08, Judy You <[email protected]> wrote:
>
>> Dear Nick:
>>
>> Sorry, i have not included the whole list of codes in my first email,
>> only with selected codes.
>>
>> Here are the complete list, and your help is much appreciated indeed.
>>
>>
>> macros:
>>                r(by) : "sla"
>>               r(c95) : "`"5050"'"
>>               r(c94) : "`"5000"'"
>>               r(c93) : "`"4809"'"
>>               r(c92) : "`"4700"'"
>>               r(c91) : "`"4650"'"
>>               r(c90) : "`"4600"'"
>>               r(c89) : "`"4409"'"
>>               r(c88) : "`"4050"'"
>>               r(c87) : "`"4030"'"
>>               r(c86) : "`"4020"'"
>>               r(c85) : "`"4009"'"
>>               r(c84) : "`"3800"'"
>>               r(c83) : "`"3650"'"
>>               r(c82) : "`"3609"'"
>>               r(c81) : "`"3409"'"
>>               r(c80) : "`"3309"'"
>>               r(c79) : "`"3209"'"
>>               r(c78) : "`"3030"'"
>>               r(c77) : "`"3009"'"
>>               r(c76) : "`"2824"'"
>>               r(c75) : "`"2818"'"
>>               r(c74) : "`"2814"'"
>>               r(c73) : "`"2811"'"
>>               r(c72) : "`"2808"'"
>>               r(c71) : "`"2806"'"
>>               r(c70) : "`"2804"'"
>>               r(c69) : "`"2802"'"
>>               r(c68) : "`"2530"'"
>>               r(c67) : "`"2500"'"
>>               r(c66) : "`"2409"'"
>>               r(c65) : "`"2380"'"
>>               r(c64) : "`"2360"'"
>>               r(c63) : "`"2340"'"
>>               r(c62) : "`"2320"'"
>>               r(c61) : "`"2308"'"
>>               r(c60) : "`"2304"'"
>>               r(c59) : "`"2270"'"
>>               r(c58) : "`"2240"'"
>>               r(c57) : "`"2200"'"
>>               r(c56) : "`"2100"'"
>>               r(c55) : "`"2000"'"
>>               r(c54) : "`"1909"'"
>>               r(c53) : "`"1809"'"
>>               r(c52) : "`"1609"'"
>>               r(c51) : "`"1409"'"
>>               r(c50) : "`"1350"'"
>>               r(c49) : "`"1209"'"
>>               r(c48) : "`"1169"'"
>>               r(c47) : "`"1138"'"
>>               r(c46) : "`"1134"'"
>>               r(c45) : "`"1128"'"
>>               r(c44) : "`"1124"'"
>>               r(c43) : "`"1118"'"
>>               r(c42) : "`"1114"'"
>>               r(c41) : "`"1108"'"
>>               r(c40) : "`"1104"'"
>>               r(c39) : "`"1098"'"
>>               r(c38) : "`"1094"'"
>>               r(c37) : "`"1088"'"
>>               r(c36) : "`"1084"'"
>>               r(c35) : "`"1078"'"
>>               r(c34) : "`"1074"'"
>>               r(c33) : "`"1068"'"
>>               r(c32) : "`"1064"'"
>>               r(c31) : "`"1058"'"
>>               r(c30) : "`"1054"'"
>>               r(c29) : "`"1052"'"
>>               r(c28) : "`"1048"'"
>>               r(c27) : "`"1044"'"
>>               r(c26) : "`"1038"'"
>>               r(c25) : "`"1034"'"
>>               r(c24) : "`"1028"'"
>>               r(c23) : "`"1024"'"
>>               r(c22) : "`"1018"'"
>>               r(c21) : "`"1014"'"
>>               r(c20) : "`"1011"'"
>>               r(c19) : "`"1008"'"
>>               r(c18) : "`"1004"'"
>>               r(c17) : "`"809"'"
>>               r(c16) : "`"790"'"
>>               r(c15) : "`"770"'"
>>               r(c14) : "`"759"'"
>>               r(c13) : "`"700"'"
>>               r(c12) : "`"600"'"
>>               r(c11) : "`"570"'"
>>               r(c10) : "`"540"'"
>>                r(c9) : "`"400"'"
>>                r(c8) : "`"360"'"
>>                r(c7) : "`"330"'"
>>                r(c6) : "`"300"'"
>>                r(c5) : "`"208"'"
>>                r(c4) : "`"207"'"
>>                r(c3) : "`"205"'"
>>                r(c2) : "`"203"'"
>>                r(c1) : "`"201"'"
>>
>>
>> Thanks
>>
>> Cheers
>>
>> Judy
>> 2011/8/2 Nick Cox <[email protected]>:
>>>
>>> You don't show the exact code you used to provoke such an error message.
>>>
>>> Nick
>>>
>>> On 2 Aug 2011, at 02:12, Judy You <[email protected]> wrote:
>>>
>>>> Dear Nick,
>>>>
>>>> i have tried your command, it gives me error message.
>>>>
>>>> matrices:
>>>>               r(se) :  1 x 95
>>>>               r(ub) :  1 x 95
>>>>               r(lb) :  1 x 95
>>>>              r(adj) :  1 x 95
>>>>            r(crude) :  1 x 95
>>>>             r(Nobs) :  1 x 95
>>>> number of observations will be reset to 95
>>>> Press any key to continue, or Break to abort
>>>> obs was 0, now 95
>>>> (95 missing values generated)
>>>> type mismatch
>>>> r(109);
>>>>
>>>> end of do-file
>>>>
>>>> r(109);
>>>>
>>>> What i like to have SLAs (area codes) maintain the original source
>>>> (numeric format),eg., sla=201, 203 205 --- 4809, 5000 5050 etc..
>>>> instead of 1 to 95.
>>>>
>>>> Cheers
>>>>
>>>> Judy
>>>>
>>>>
>>>>
>>>> 2011/7/13 Judy You <[email protected]>
>>>>>
>>>>> Thanks Nick for your promptous response. SLA is an area code. Since i
>>>>> am away and have no stata program in my hand, i ccouldn't try to run
>>>>> it now, but i trust it will work fine.
>>>>>
>>>>> Cheers
>>>>>
>>>>> Judy
>>>>>
>>>>>
>>>>> 2011/7/11 Nick Cox <[email protected]>:
>>>>>>
>>>>>> I don't know what SLAs are.
>>>>>>
>>>>>> In your case, the row names, originally column names, are apparently
>>>>>> all
>>>>>> numbers, so you should be able to loop over the names and store them
>>>>>> in a
>>>>>> variable (_not_ column) something like this:
>>>>>>
>>>>>> qui dstdize freq pop sex agegp, by(sla) using (t0)
>>>>>>
>>>>>> drop _all
>>>>>> return list
>>>>>> matrix C = r(crude)', r(adj)', r(lb)' , r(ub)'
>>>>>> svmat C, names(col)
>>>>>>
>>>>>> gen rowname = .
>>>>>> qui forval i = 1/95 {
>>>>>>      replace rowname = r(c`i') in `i'
>>>>>> }
>>>>>>
>>>>>> Nick
>>>>>> [email protected]
>>>>>>
>>>>>> Judy You
>>>>>>
>>>>>> I am running a "dstdize" age-standardised rate syntax and got a result
>>>>>> with Crude and age-adjusted rate, together with lower and upper limit.
>>>>>>
>>>>>> The age adjusted rate is reported by SLA level (which there are 95
>>>>>> rows or records). I have save the matrix in a file but the result
>>>>>> doesn't come along with SLA code. I could force it to do by merge the
>>>>>> predefined file with sla code to the one saved in the matrix. I
>>>>>> believer there should be the smart way to do.
>>>>>>
>>>>>> Here is my log file. Thanks for your help in advance!
>>>>>>
>>>>>> ----------
>>>>>>
>>>>>> . qui dstdize freq pop sex agegp, by(sla) using (t0)
>>>>>>
>>>>>> . drop _all
>>>>>>
>>>>>> . return list
>>>>>>
>>>>>> scalars:
>>>>>>                r(k) =  95
>>>>>>
>>>>>> macros:
>>>>>>               r(by) : "sla"
>>>>>>              r(c95) : "`"5050"'"
>>>>>>              r(c94) : "`"5000"'"
>>>>>>              r(c93) : "`"4809"'"
>>>>>> ------
>>>>>>               r(c3) : "`"205"'"
>>>>>>               r(c2) : "`"203"'"
>>>>>>               r(c1) : "`"201"'"
>>>>>>
>>>>>> matrices:
>>>>>>               r(se) :  1 x 95
>>>>>>               r(ub) :  1 x 95
>>>>>>               r(lb) :  1 x 95
>>>>>>              r(adj) :  1 x 95
>>>>>>            r(crude) :  1 x 95
>>>>>>             r(Nobs) :  1 x 95
>>>>>>
>>>>>> . matrix C = r(crude)', r(adj)', r(lb)' , r(ub)'
>>>>>>
>>>>>> . svmat C, names(col)
>>>>>> number of observations will be reset to 95 Press any key to continue,
>>>>>> or Break to abort obs was 0, now 95
>>>>>>
>>>>>> . save t1,replace
>>>>>> file t1.dta saved
>>>>>>
>>>>>> Crude   Adjusted        Left    Right
>>>>>> .0144418        .0213993        .0160632        .0267354
>>>>>> .0242798        .0409689        .030746 .0511917
>>>>>> .0123417        .0186174        .0149574        .0222773
>>>>>> .0097357        .0142612        .0108197        .0177028
>>>>>> .0260393        .051086 .0389991        .0631729
>>>>>>
>>>>>> -----
>>>>>>
>>>>>>
>>>>>> The saved file looks like that, but what I like is to have a column
>>>>>> named as SLA, corresponding to the SLA codes in the original data.
>>>>>> Could any expert give me some hint?
>>>>>>
>>>>>>
>>>>
>>>
> *
> *   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/
>

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


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