Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Nested locals?


From   Neil Shephard <[email protected]>
To   [email protected]
Subject   st: Nested locals?
Date   Fri, 5 Jun 2009 16:13:25 +0100

Hi,

I'm trying to take the output from running -dstdize- and derive a
Stata formatted data set.

At present I have the following code (which can no doubt be improved
upon, but thats not why I'm posting)...

/*************************************************************************/
/* Start code                                             */
/*************************************************************************/

  dstdize n pop agegrp, by(pct stage) using(s:/common/data/stata/europops)

  /* Save the results (from the matrix that they are stored in) to a    */
  /* Stata formatted data set                                           */
  mat define incidence = 100000 * r(adj)
  mat define lci       = 100000 * r(lb)
  mat define uci       = 100000 * r(ub)

  /* Clear the data in memory and save the matrix of results instead    */
  clear
  svmat incidence
  svmat lci
  svmat uci

  /* Reshape and label each of the data points                          */
  gen id = _n
  reshape long incidence lci uci, i(id) j(site_group)
  drop in 1

/*************************************************************************/
/* End code                                             */
/*************************************************************************/

This gets me the results in the correct format, but there is no
labelling as to which data is which.

Looking at whats returned after running -dstdize- it seems that the
levels of -by(pct stage)- are stored in scalars that I'm now trying to
get at so I can label the results, but I'm scratching my head over
what I'd call nested macro's and have been trying various combinations
of compound double quotes.

The scalars and matrices returned after running -dstdize-......

. return list

scalars:
                  r(k) =  84

macros:
                 r(by) : "pct stage"
                r(c84) : "`"5PD"' `"."'"
                r(c83) : "`"5PD"' `"4"'"
                r(c82) : "`"5PD"' `"3"'"
                r(c81) : "`"5PD"' `"2"'"
                r(c80) : "`"5PD"' `"1"'"
                r(c79) : "`"5PD"' `"0"'"
                r(c78) : "`"5PC"' `"."'"
                r(c77) : "`"5PC"' `"4"'"
                r(c76) : "`"5PC"' `"3"'"
                r(c75) : "`"5PC"' `"2"'"
                r(c74) : "`"5PC"' `"1"'"
                r(c73) : "`"5PC"' `"0"'"
                r(c72) : "`"5PA"' `"."'"
                r(c71) : "`"5PA"' `"8"'"
                r(c70) : "`"5PA"' `"4"'"
                r(c69) : "`"5PA"' `"3"'"
                r(c68) : "`"5PA"' `"2"'"
                r(c67) : "`"5PA"' `"1"'"
                r(c66) : "`"5PA"' `"0"'"
                r(c65) : "`"5N9"' `"."'"
                r(c64) : "`"5N9"' `"8"'"
                r(c63) : "`"5N9"' `"4"'"
                r(c62) : "`"5N9"' `"3"'"
                r(c61) : "`"5N9"' `"2"'"
                r(c60) : "`"5N9"' `"1"'"
                r(c59) : "`"5N9"' `"0"'"
                r(c58) : "`"5N8"' `"."'"
                r(c57) : "`"5N8"' `"4"'"
                r(c56) : "`"5N8"' `"3"'"
                r(c55) : "`"5N8"' `"2"'"
                r(c54) : "`"5N8"' `"1"'"
                r(c53) : "`"5N8"' `"0"'"
                r(c52) : "`"5N7"' `"."'"
                r(c51) : "`"5N7"' `"4"'"
                r(c50) : "`"5N7"' `"3"'"
                r(c49) : "`"5N7"' `"2"'"
                r(c48) : "`"5N7"' `"1"'"
                r(c47) : "`"5N7"' `"0"'"
                r(c46) : "`"5N6"' `"."'"
                r(c45) : "`"5N6"' `"8"'"
                r(c44) : "`"5N6"' `"4"'"
                r(c43) : "`"5N6"' `"3"'"
                r(c42) : "`"5N6"' `"2"'"
                r(c41) : "`"5N6"' `"1"'"
                r(c40) : "`"5N6"' `"0"'"
                r(c39) : "`"5N5"' `"."'"
                r(c38) : "`"5N5"' `"4"'"
                r(c37) : "`"5N5"' `"3"'"
                r(c36) : "`"5N5"' `"2"'"
                r(c35) : "`"5N5"' `"1"'"
                r(c34) : "`"5N5"' `"0"'"
                r(c33) : "`"5N4"' `"."'"
                r(c32) : "`"5N4"' `"8"'"
                r(c31) : "`"5N4"' `"4"'"
                r(c30) : "`"5N4"' `"3"'"
                r(c29) : "`"5N4"' `"2"'"
                r(c28) : "`"5N4"' `"1"'"
                r(c27) : "`"5N4"' `"0"'"
                r(c26) : "`"5JE"' `"."'"
                r(c25) : "`"5JE"' `"4"'"
                r(c24) : "`"5JE"' `"3"'"
                r(c23) : "`"5JE"' `"2"'"
                r(c22) : "`"5JE"' `"1"'"
                r(c21) : "`"5JE"' `"0"'"
                r(c20) : "`"5H8"' `"."'"
                r(c19) : "`"5H8"' `"4"'"
                r(c18) : "`"5H8"' `"3"'"
                r(c17) : "`"5H8"' `"2"'"
                r(c16) : "`"5H8"' `"1"'"
                r(c15) : "`"5H8"' `"0"'"
                r(c14) : "`"5ET"' `"."'"
                r(c13) : "`"5ET"' `"4"'"
                r(c12) : "`"5ET"' `"3"'"
                r(c11) : "`"5ET"' `"2"'"
                r(c10) : "`"5ET"' `"1"'"
                 r(c9) : "`"5ET"' `"0"'"
                 r(c8) : "`"5EM"' `"."'"
                 r(c7) : "`"5EM"' `"8"'"
                 r(c6) : "`"5EM"' `"4"'"
                 r(c5) : "`"5EM"' `"3"'"
                 r(c4) : "`"5EM"' `"2"'"
                 r(c3) : "`"5EM"' `"1"'"
                 r(c2) : "`"5EM"' `"0"'"
                 r(c1) : "`""' `"."'"

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


I'm close but can't get the last step as I'm using the following code
(_before_ the -reshape-)...

  /* Save the scalars so that they can be used to derive the categories */
  /* for each of the resulting statistics                               */
  local n = r(k)
  forval x = 1/`n'{
      local _`x' `r(c`x')'
     di `"_`x'"'  // <-- In so I can see if I'm getting it right!
   }

But this outputs "_1", "_2" etc. instead of the corresponding value of
"`"5PD"' `"."'" , "`"5PD"' `"4"'" etc.

I've tried all variations that I can think of quotes/double quotes,
but none seem to work.

Had a good google but couldn't find anything that helped.  I suspect
I'm missing something obvious but would appreciate pointers to any
resources that help solve this.

Regards,

Neil


-- 
"The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data." ~ John Tukey (1986), "Sunset salvo". The American
Statistician 40(1).

Email - [email protected]
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index