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: -svmat- with matrix colnames based on factor variable names?


From   <[email protected]>
To   <[email protected]>
Subject   Re: st: -svmat- with matrix colnames based on factor variable names?
Date   Mon, 14 Feb 2011 15:56:08 -0000

Many thanks to Nick and Scott. Very helpful solutions -- thank you.
Nick's idea of putting the details in the variable labels rather than
the names is obvious (in hindsight). Scott's solves the original problem
and usefully teaches me about an undocumented command I was unaware of
(-help _ms_parse_parts-).

Apologies for posting my message twice. I checked the Archives and noted
that my first message didn't show after quite a few hours. Hence the
re-post. So, now I'm unsure how long it takes for posts to be archived
(in the StataCorp version). But that's a different thread.

Stephen

------------------------------

Date: Sat, 12 Feb 2011 11:16:01 +0000
From: Nick Cox <[email protected]>
Subject: Re: st: -svmat- with matrix colnames based on factor variable
names?

I am not following all the details here, but how far does something
like this help?

svmat at
matnames at
local nvars : word count `r(c)'
tokenize "`r(c)''"
forval i = 1/`nvars' {
label var at`i' `"``i'''"'
}

That is, put the details in the variable labels.
------------------------------
------------------------------

Date: Sat, 12 Feb 2011 20:46:38 -0600
From: Scott Merryman <[email protected]>
Subject: Re: st: -svmat- with matrix colnames based on factor variable
names?

On Sat, Feb 12, 2011 at 4:49 AM,  <[email protected]> wrote:
> The workaround I was seeking was a quick/easy/automated way of going
> from what is shown as the contents of r(c) after -matnames- to a list
of
> valid variable names that preserves the essential information. The new
> list can be used to re-label the matrix prior to -svmat-. The new
names
> could be based, for instance, on the old ones but drop the ":" and "."
> from the elements of r(c), and add some prefix ("_", say) to each of
the
> elements. My efforts using -subinstr- and also regular expression
> functions were not productive, but that is probably a comment on my
> skills.

Something like this?

clear*
webuse nhanes2f
logit diabetes i.hsizgp  i.black i.female age i.female#c.age, nolog

margins , at(female = 1  age = 40 hsizgp = (1(1)5) )
mat at = r(at)
matnames at
local a = r(c)
foreach l of local a {
	_ms_parse_parts `l'
	local names = "`names' `=r(name)'_`r(level)' "
}
matrix colnames at = `names'
mat list at
svmat at, names(col)


Scott
=================================

Stephen
------------------
Stephen P. Jenkins <[email protected]>
Department of Social Policy and STICERD/CASE
London School of Economics and Political Science
Houghton Street
London WC2A 2AE
United Kingdom
Tel: +44(0)20 7955 6527
Survival Analysis Using Stata:
http://www.iser.essex.ac.uk/survival-analysis
Downloadable papers and software: http://ideas.repec.org/e/pje7.html


Please access the attached hyperlink for an important electronic communications disclaimer: http://lse.ac.uk/emailDisclaimer

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