Announcement

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

  • How to break down the values of one columns to different columns?

    Hi
    In my survey, I had a ranked order question. I asked the participants to rank 6 variables from 1 to 6.
    The dataset is arranged like bellow for this specific question: ("- - - - -" indicates missing)
    ranking
    4 - 6 - 2 - 3 - 5 - 1
    6 - 4 - 5 - 2 - 3 - 1
    - - - - -
    2 - 4 - 6 - 5 - 3 - 1
    6 - 2 - 4 - 5 - 3 - 1
    - - - - -
    - - - - -
    - - - - -
    5 - 4 - 6 - 2 - 3 - 1
    Currently, Stata considers its storage type as str21 and I need to change it to a numeric type.

    How can I break the variable ranking into six different variables: R_var1, R_var2, ..., R_var6 (which means the ranking of var1, ranking of var2, and so on)

    Thanks for the recommendations.

  • #2
    You could use -split-.

    .ÿ
    .ÿversionÿ17.0

    .ÿ
    .ÿclearÿ*

    .ÿ
    .ÿquietlyÿinputÿstr40ÿranking

    .ÿ
    .ÿquietlyÿsplitÿranking,ÿgenerate(R_var)ÿparse(-)ÿdestring

    .ÿ
    .ÿlist,ÿnoobsÿseparator(0)

    ÿÿ+-----------------------------------------------------------------------------+
    ÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿrankingÿÿÿR_var1ÿÿÿR_var2ÿÿÿR_var3ÿÿÿR_var4ÿÿÿR_var5ÿÿÿR_var6ÿ|
    ÿÿ|-----------------------------------------------------------------------------|
    ÿÿ|ÿ4ÿ-ÿ6ÿ-ÿ2ÿ-ÿ3ÿ-ÿ5ÿ-ÿ1ÿÿÿÿÿÿÿÿ4ÿÿÿÿÿÿÿÿ6ÿÿÿÿÿÿÿÿ2ÿÿÿÿÿÿÿÿ3ÿÿÿÿÿÿÿÿ5ÿÿÿÿÿÿÿÿ1ÿ|
    ÿÿ|ÿ6ÿ-ÿ4ÿ-ÿ5ÿ-ÿ2ÿ-ÿ3ÿ-ÿ1ÿÿÿÿÿÿÿÿ6ÿÿÿÿÿÿÿÿ4ÿÿÿÿÿÿÿÿ5ÿÿÿÿÿÿÿÿ2ÿÿÿÿÿÿÿÿ3ÿÿÿÿÿÿÿÿ1ÿ|
    ÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿ-ÿ-ÿ-ÿ-ÿ-ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿ|
    ÿÿ|ÿ2ÿ-ÿ4ÿ-ÿ6ÿ-ÿ5ÿ-ÿ3ÿ-ÿ1ÿÿÿÿÿÿÿÿ2ÿÿÿÿÿÿÿÿ4ÿÿÿÿÿÿÿÿ6ÿÿÿÿÿÿÿÿ5ÿÿÿÿÿÿÿÿ3ÿÿÿÿÿÿÿÿ1ÿ|
    ÿÿ|ÿ6ÿ-ÿ2ÿ-ÿ4ÿ-ÿ5ÿ-ÿ3ÿ-ÿ1ÿÿÿÿÿÿÿÿ6ÿÿÿÿÿÿÿÿ2ÿÿÿÿÿÿÿÿ4ÿÿÿÿÿÿÿÿ5ÿÿÿÿÿÿÿÿ3ÿÿÿÿÿÿÿÿ1ÿ|
    ÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿ-ÿ-ÿ-ÿ-ÿ-ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿ|
    ÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿ-ÿ-ÿ-ÿ-ÿ-ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿ|
    ÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿ-ÿ-ÿ-ÿ-ÿ-ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿÿÿÿÿÿÿÿ.ÿ|
    ÿÿ|ÿ5ÿ-ÿ4ÿ-ÿ6ÿ-ÿ2ÿ-ÿ3ÿ-ÿ1ÿÿÿÿÿÿÿÿ5ÿÿÿÿÿÿÿÿ4ÿÿÿÿÿÿÿÿ6ÿÿÿÿÿÿÿÿ2ÿÿÿÿÿÿÿÿ3ÿÿÿÿÿÿÿÿ1ÿ|
    ÿÿ+-----------------------------------------------------------------------------+

    .ÿ
    .ÿexit

    endÿofÿdo-file


    .


    Code:
    help split

    Comment


    • #3
      Try

      Code:
      split ranking, parse("-")
      and if it does not work, provide a sample of your data using -dataex-.

      Comment


      • #4
        @Joseph Coveney and @Joro Kolev

        Thanks a lot for your quick responses.

        It worked successfully :-)

        Comment

        Working...
        X