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: dropping matrix columns


From   Sergiy Radyakin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: dropping matrix columns
Date   Thu, 12 Dec 2013 12:03:54 -0500

set more off
clear

matrix A=1,2,.,3,.\ 5,3,.,8,. \ 9,0,.,2,.
matrix colnames A=1 2 3 4 5
matrix list A

tempname B
local r=rowsof(A)
forval c=1/`=colsof(A)' {
  mata st_numscalar("mx",max(st_matrix("A")[.,`c']))
  if (mx<.) matrix `B'= nullmat(`B'), A[1..`r',`c']
}

matrix A=`B'
svmat A
list
******* Sergiy Radyakin *************



On Thu, Dec 12, 2013 at 11:56 AM, Nick Cox <[email protected]> wrote:
> -svmat- really is an anomaly. I can remember comments about the end of
> the last century, and I am being literal and not exaggerating, that it
> was due for an overhaul, which never came. But then came Mata and -- I
> am imputing a missing statement here -- the implication is that it is
> superseded but remains available so as not to break any existing
> programs or do-files. It's not worth any developer time to update
> something in that condition. It would be like adding an engine to a
> donkey.
>
> So, the short and general answer is: Don't write anything now using
> -svmat-. There will be a much better way to do what you want using
> Mata. In particular, check out -putmata- and -getmata-.
>
> Nick
> [email protected]
>
>
> On 12 December 2013 16:40,  <[email protected]> wrote:
>>  Dear Stata Users,
>>
>> I am using a loop in which many large matrices are created. I want to use (each of) these matrices to create a single new dataset using the -svmat- command. For each of the matrices many of the column names start with a number AND are the columns empty. Since variable names that start with a number are not allowed -svmat- does not work, i.e. I first need to either change get rid of the first numbers in the column names or delete these columns ( I dont need them).
>> How can I tell stata to drop all matrix columns for which the name starts with a number OR tell stata to drop all columns in a matrix that are entirely empty?
>>
>> Many thanks
>>
>> Darjusch
>>
>> *
>> *   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/

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