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


From   Kieran McCaul <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: building macros with results of each loop enclosed in double quotes
Date   Wed, 29 Jan 2014 13:14:58 +0800

...

When you're adding a new label to the end of `alllabs', you need to enclose it all between `" and "'

Like this:

local one = "label1"
local two = "label2"
local three = "label3"


local alllabs `""`one'" "'
di `"`alllabs '"'
local alllabs  `" `alllabs '"`two'" "'
di `"`alllabs '"'
local alllabs  `" `alllabs '"`three'" "'
di `"`alllabs '"'


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Brent McSharry (ADHB)
Sent: Wednesday, 29 January 2014 11:34 AM
To: [email protected]
Subject: st: building macros with results of each loop enclosed in double quotes

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/

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