Announcement

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

  • #16
    Hello everyone!
    I want to generate the count of 1's across each provision, but I want to leave out some provisions. For example, in the dataex below, I want this count only for two-digit provisions, leaving out all three-digit provisions.

    when i run the following code

    Code:
    egen count = rowtotal(prov08-prov15)
    This generates the count across all the provisions, but I want to leave three-digit provisions (prov100; prov101; prov103; ....prov110; prov111; prov112; ....prov130; prov131; prov132) from the count.

    How can I do that?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str2(state_i state_k) int year byte(prov08 prov09 prov10 prov100 prov101 prov103 prov11 prov110 prov111 prov112 prov13 prov130 prov131 prov132 prov14 prov15)
    "JK" "BR" 1990 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
    "JK" "BR" 1991 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    "JK" "BR" 1992 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    "JK" "LT" 1990 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0
    "JK" "LT" 1992 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    "JK" "TR" 1990 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0
    "JK" "TR" 1991 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
    "JK" "TR" 1992 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    "ST" "AS" 1990 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    "ST" "AS" 1991 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
    "ST" "BR" 1990 1 1 1 1 0 1 0 0 0 1 1 0 0 1 0 1
    "ST" "BR" 1992 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0
    "ST" "LT" 1990 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    "ST" "LT" 1991 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0
    "ST" "LT" 1992 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
    end
    Thanks and regards

    (Ridwan)

    Comment


    • #17
      Code:
      rowtotal(prov??)
      using so-called wildcard syntax as documented e.g. at

      Code:
      help varlist

      Comment


      • #18
        Thank you very much, Nick Cox

        It worked fine

        regards,
        (Ridwan)

        Comment


        • #19
          Sorry Nick Cox, for bothering you again. Actually I require different counts across different dimensions of each provision. That is;
          First, I want to generate count1 from prov_01-prov_04, the previous codes work fine here
          Code:
          egen count1 = rowtotal(prov_01-prov_04)
          Next, i want to generate count2 from prov_06 - prov_14, however, here I want to leave the three-digit provisions (prov_130, prov_131, prov_132, prov_134) from the calculation. The earlier code rowtotal(prov_??)worked fine in the previous example as sated and does count across all the columns with two-digit provisions. I want to ask, how can i generate count2 within this subset (prov_06 - prov_14), leaving out the three digit provision codes. ?

          Finally, i want to generate
          count3 from prov_21 - prov_23, the previous codes work fine here
          Code:
          egen count3 = rowtotal(prov_21-prov_23)
          I have difficulty in generating count2 across the sub-class of prov_#-prov_# leaving out three digit provisions within this sub-class .


          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str2(state_i state_k) int year byte(prov_01 prov_02 prov_03 prov_04 prov_06 prov_07 prov_08 prov_10 prov_11 prov_12 prov_13 prov_130 prov_131 prov_132 prov_134 prov_14 prov_21 prov_22 prov_23 prov_24)
          "JK" "BR" 1990 0 0 0 1 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0
          "JK" "BR" 1991 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0
          "JK" "BR" 1992 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
          "JK" "LT" 1990 0 0 0 0 1 0 1 0 1 0 0 0 1 1 1 0 0 0 0 0
          "JK" "LT" 1992 0 0 0 0 0 0 0 0 1 1 1 0 0 1 1 0 0 1 0 1
          "JK" "TR" 1990 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1
          "JK" "TR" 1991 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 1 1 1
          "JK" "TR" 1992 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1
          "ST" "AS" 1990 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1
          "ST" "AS" 1991 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0
          "ST" "BR" 1990 1 0 1 1 0 0 0 0 0 1 1 1 0 0 1 1 0 0 0 1
          "ST" "BR" 1992 1 0 0 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0
          "ST" "LT" 1990 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0
          "ST" "LT" 1991 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
          "ST" "LT" 1992 0 0 0 0 1 1 1 0 0 0 1 0 0 0 1 1 0 0 0 0
          end
          Thanks,
          (Ridwan)

          Comment


          • #20
            I suggest that you use
            Code:
            order
            to get your variables in a more convenient order.

            Comment


            • #21
              Thanks a lot, Nick Cox

              This suggestion worked better

              Code:
              order prov_130 prov_131 prov_132 prov_134, a(prov_14)
              Code:
              egen count2 = rowtotal(prov_06-prov_14)
              This does what I needed.

              Thanks a ton

              (Ridwan)

              Comment

              Working...
              X