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: building macros with results of each loop enclosed in double quotes


From   "Brent McSharry (ADHB)" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: building macros with results of each loop enclosed in double quotes
Date   Wed, 29 Jan 2014 16:33:32 +1300

G'day

I am trying to create output for a macro, easiest to describe by creating a small ado file to replicate (assuming you have a variable with value labels assigned):

program testquotes
version 10.1
syntax varname
	local vallbl:value label `varlist'
	levelsof `varlist', local(lvls)
	tokenize `lvls'
	while "`*'" != "" {
		local currentlab:label `vallbl' `1'
		local alllabs `alllabs' `"`currentlab'"'
		mac shift
	}
	di `alllabs'
end

when it gets to the last line (di `alllabs') alllabs is being interpreted as:

= di 0-12 months `"12months - 60months"' `"5yrs +"'

I would like to have created the alllabs macro to contain:
= "0-12 months" "12months - 60months" "5yrs +"
This way (in the more complex program), word 1 of alllabs (using macro extended functions) would be "0-12 months", word 2 "12months - 60months". 

At present, word 2 will be months.

Thanks for your help

Brent McSharry MBBS BSc(med) FCICM(paed)
Paediatric Intensivist
Starship Children's Hospital
Private Bag 92024
Auckland 1142
New Zealand 


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