Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: Utility to reduce vector length by a given number of elements


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: Utility to reduce vector length by a given number of elements
Date   Fri, 9 Mar 2007 18:09:02 -0000

Perhaps more important than any of this is that
you can program whatever it is that you want. 

At one stage I wanted a program to select rows 
and columns from a matrix and it is accessible
as -matselrc- in the files for -dm79-. These days 
I would use Mata instead, but that program, and 
other things, remain accessible and 
might help you write your own. 

For example

STB-56  dm79  . . . . . . . . . . . . . . . . . . Yet more new matrix commands
        (help matcorr, matewmf, matvsort, svmat2 if installed)  . .  N. J. Cox
        7/00    pp.4--8; STB Reprints Vol 10, pp.17--23
        commands to produce a correlation matrix, elementwise monadic
        function of another matrix, selected subsets of matrix rows
        and columns, vec or vech of a matrix, elements sorted within
        a vector, matrix from a vector, and commands to save matrices

STB-50  dm69  . . . . . . . . . . . . . . . . . .  Further new matrix commands
        (help matdelrc, matewm, matmad, matpow if installed)  . . .  N. J. Cox
        7/99    pp.5--9; STB Reprints Vol 9, pp.29--34
        collection of new matrix commands providing additional matrix
        checking, management, element-wise operators, maximum absolute
        difference, and power

STB-39  dm49  . . . . . . . . . . . . . . . . . . . . Some new matrix commands
        (help matfunc, varfunc if installed)  . . . . . . . . . . .  J. Weesie
        9/97    pp.17--20; STB Reprints Vol 7, pp.43--48
        collection of new matrix commands; several for explicit matrices
        and a few for implicit matrices (i.e., variables)

However, the minimal syntax would have to be 
	what is your matrix 
	what do you want to omit 

and my guess is that whatever you wrote would be no 
easier to use -- and less flexible -- than existing commands. 

Nick 
[email protected] 

> -----Original Message-----
> From: Nick Cox 
> Sent: 09 March 2007 15:19
> To: '[email protected]'
> Subject: RE: st: RE: Utility to reduce vector length by a given number
> of elements
> 
> 
> It can be done in one line too: 
> 
> mat a = a[1, 1 .. `=colsof(a) - 5']
> 
> There is a slippery slope here. First, once
> you know that you can do things like that above, 
> you realise you don't need a specific extra function.
> 
> In principle, the idea that there should be
> a function to solve each problem sounds good, 
> but who decides what counts as a problem
> and who ends up dealing with the consequences? 
> 
> For example, a language with 1000 functions isn't 
> necessarily better than one with 100 functions. It could 
> just become 10 times more difficult to document, to 
> read and to learn. 
> 
> In any case, there may be other solutions; it's just
> that I have not thought of them. 
> 
> Nick 
> [email protected] 
> 
> Rachel
>  
> > Thanks Nick, this works.  I was hoping for a one step command
> > (analagous to the   functionality for strings in your -renvars-
> > command) that did not involve computing the length, but apparently
> > this doesn't exist.
> > 
> > On 3/8/07, Nick Cox <[email protected]> wrote:
> > > You may not know the length, but Stata does, so
> > > does this suit?
> > >
> > > . matrix a = (1,2,3,4,5,6,7,8,9,10)
> > >
> > > . mat list a
> > >
> > > a[1,10]
> > >      c1   c2   c3   c4   c5   c6   c7   c8   c9  c10
> > > r1    1    2    3    4    5    6    7    8    9   10
> > >
> > > . local last  = colsof(a) - 5
> > >
> > > . matrix a = a[1, 1..`last']
> > >
> > > . mat list a
> > >
> > > a[1,5]
> > >     c1  c2  c3  c4  c5
> > > r1   1   2   3   4   5
> > >
> > >
> > > Nick
> > > [email protected]
> > >
> > > Rachel
> > >
> > > > Is there a Stata (rather than Mata) utility that will 
> > remove the last
> > > > n elements of a vector?  Is there some way of doing this without
> > > > explicitly without knowing (or evaluating) the length of 
> > the vector?
> 

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