Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • using findname varlist to delete some variables

    Dear All,


    I might have an easy question, but I could not solve it.

    I have many datasets containing symmetric matrices like this one:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int id double(n50 n51 n52 n53 n54 n55 n56 n57 n58 n59 n60)
    50                0                  0                  0 0                  0                  0 38.3389379109718 0 0                  0 0
    51                0                  0                  0 0 25.236151069051278                  0                0 0 0                  0 0
    52                0                  0                  0 0                  0 13.503105903401261                0 0 0                  0 0
    53                0                  0                  0 0                  0                  0                0 0 0                  0 0
    54                0 25.236151069051278                  0 0                  0 25.236151069051278                0 0 0                  0 0
    55                0                  0 13.503105903401261 0 25.236151069051278                  0                0 0 0 15.140474533964072 0
    56 38.3389379109718                  0                  0 0                  0                  0                0 0 0                  0 0
    57                0                  0                  0 0                  0                  0                0 0 0                  0 0
    58                0                  0                  0 0                  0                  0                0 0 0                  0 0
    59                0                  0                  0 0                  0 15.140474533964072                0 0 0                  0 0
    60                0                  0                  0 0                  0                  0                0 0 0                  0 0
    end

    As you can see, the variables and the ids are the same except the beginning "n". These matrices are full, but some of them - like the variable n60 and the row 60 are all zero. Some datasets I am using even do not have all zero variables.

    I can detect the ones containing all zeros by using findname, all(@ == 0), and it provides me the varlist such as n60.
    For all datasets, I wish to detect and delete the ones containing all zeros and again create a symmteric matrix, then create an id list and save them. For the ones that do not contain all zero variables, I wish to check by findname, do nothing else but create an id list and save them.

    I tried egen=anymatch (id), (numlist), but I have a varlist, not numlist. Thus, it did not work.

    How can I do that?

    I hope I could explain my problem clearly. I appreciate any help.

    Thank you in advance.

    Sevgi
Working...
X