Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: trying to combine local macro and "format" command in a loop


From   Woolton Lee <finished07@gmail.com>
To   statalist <statalist@hsphsun2.harvard.edu>
Subject   st: trying to combine local macro and "format" command in a loop
Date   Thu, 5 May 2011 12:57:08 -0400

Thank you to Maarten Buis for help in bringing some resolution to my
ongoing problem.  I've modified my code so that it now attempts to
format the local macros created so that

1) they are rounded to two decimals
2) the assigned format matches the length of the string stored in a macro

These local macros are used in a postfile command to store the results
in a table.  I'm using the following code to set the format of each
macro so that it matches the actual length of the numeric value.  The
variables included vary in length for example age is like 52.34, while
total charges (tchg) can be something like 539202.12.  I use the
function length to set a local macro for the mean and for the length
of the standard deviation of each variable and then attempt to set the
format.

/* continuous variables - Lung */
local vars2 age los tchg costpd rbchg rcchg scchg aneschg phrchg radchg mrict
		nmchg clchg orchg msschg othchg;
forvalues x = 1/16 {;
	local v: word `x' of `vars2';
/********* insurance by safety net hospital */
	forvalues a = 1/4 {;
		local i: word `a' of `ins';
		sum `v' if vhi_site == "Lung" & `i' == 1 & snh == 1 & link_lung == 1;
		local lm = length(r(mean)); local ls = length(r(sd));
		local mn`v'_snh`i': display %`lm'.2f r(mean);
		local std`v'_snh`i': display %`ls'.2f r(sd);
	};

However, STATA gives me the following error.

type mismatch

Any ideas how to fix this problem so that in the loop each macro is
assigned its ROUNDED length?

Thanks for your help,

W





© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index