Announcement

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

  • Combine multiple numeric variables to one

    Hi All ,
    Please help me ,
    I am a new learner for STATA . I would like to know : I want to make combination multiple variables to one ( numeric )

    For example ;
    in my data set :
    ID x y z
    1 2 . 7
    2 . 3 8
    3 7 . 1
    4 3 4 .
    5 . 6 .
    I would get like this
    ID t
    1 2
    1 7
    2 3
    2 8
    3 7
    3 1
    4 3
    4 4
    5 6

    Please me this

  • #2
    Thein:
    welcome to the list.
    See -reshape- (from wide to long format).
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Please note that it is always better to post real data examples. This helps people to provide you with actual code to use.
      Please see the FAQ on how to use dataex to post such examples.


      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input byte(id x y z)
      1 2 . 7
      2 . 3 8
      3 7 . 1
      4 3 4 .
      5 . 6 .
      end
      The reshape command here would need a stub to understand those x y z variables go together. Here i first add t before the reshape.

      Code:
      ren * t*
      ren tid id
      reshape long t, i(id) j() string

      Comment


      • #4
        Thanks

        Comment


        • #5
          Hi Carlo,
          Thanks for your explanation .

          I have no one issues as follows . I would like to use replace for string variables but this is no any replace made so please help how I can solve this ?


          . gen imple_compar_vill =""
          (1021 missing values generated)

          . replace imple_compar_vill = "Implement" if myanmar_village =="03"
          (0 real changes made)

          Comment


          • #6
            Thein:
            Your code shoud be:
            Code:
            gen imple_compar_vill ="."
            replace imple_compar_vill = "Implement" if myanmar_village =="03"///assuming that -myanmar_village- is string s well
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Thanks Carlo..

              Comment


              • #8
                Hi Carlo ,
                I am now labeling the variables : there is some issues for multivalues
                I have data set like this variable : available water sources ? the options are as follow , allow multiple selection so responses in the data set are likes 1 3 ...4 5 .....1 2 3...... 178 , etc because they are selected by multiple options so how can label value those kinds of multiple response . please help .
                1 Surface water (river, pond etc)
                2 Rainwater
                3 Borehole
                4 Unprotected spring or well
                5 Protected spring or well
                6 Tanker truck or cart
                7 Public tap
                8 Piped into house
                9 Bottled

                Comment


                • #9
                  Thein:
                  see -label-.
                  An excerpt of your code might be:
                  Code:
                  label define <watersources> 1 "Surface water"///and so on
                  Multivalues are simply annoying, but the general rule still applies.
                  Kind regards,
                  Carlo
                  (Stata 19.0)

                  Comment


                  • #10
                    Hi Thanks for your help,
                    I have still : label value : ( lab val q_31 <watersources> ) , that is correct ?

                    Comment


                    • #11
                      See also http://www.statalist.org/forums/foru...onses-variable

                      Comment

                      Working...
                      X