Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: saving varlist as matrix rownames


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: saving varlist as matrix rownames
Date   Wed, 17 Aug 2005 22:11:52 +0100

Various solutions. Here are some: 

(1) 

tokenize `varlist' 
local xvarlist : list varlist - 1 
matrix rownames `influence_mat' = `xvarlist' 

(2) 

local y : word 1 of `varlist' 
local xvarlist : list varlist - y 
matrix rownames `influence_mat' = `xvarlist' 

(3) 

local xvarlist : subinstr local varlist "`: word 1 of `varlist''" "" 
matrix rownames `influence_mat' = `xvarlist' 

At this instant I rather like the second best. (3) saves a line, but 
is perhaps less easy to understand on revisiting the code. 

Nick 
[email protected] 

Schonlau, Matthias
 
> I am trying to build a matrix that has k-1 rows where k is 
> the number of words in varlist.
> I am constructing the matrix by adding one row after another 
> and it works.
> (In the code below I am just filling in -1's, they are replaced later)
> I then try save the variable names of the x-variables (all 
> variables after the first one). Specifically I'd use the 
> variable names as rownames for the  matrix. 
> I can strip off the first word in varlist  with 
> regexr("`varlist'","`1'","")
> . Unfortunately when trying to assign this to a local macro 
> the length of the string 
> is cut to 80 characters.
> 
> Here is the relevant code:
> 
>  local k : word count `varlist' 
>  tempname A
>  matrix `A'=(-1)
>  matrix input `influence_mat'=(-1)
>   while (rowsof(`influence_mat')< `k'-1) {
>  	 matrix `influence_mat' = `influence_mat' \ `A'
> 
>   }
> tokenize `varlist'
> local  varlist1 = regexr("`varlist'","`1'","")  /* works, but 
> cuts down to 80? characters */
> matrix rownames `influence_mat' = `varlist1'   /* does not 
> work, conformability error */
> 							    /* 
> because varlist1 has too few entries */
> 
> 
> Any suggestions ? I also would be fine with using hte names 
> as a second column in the matrix
> but it doesn't seem like stata likes string entries in columns.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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