Announcement

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

  • Reshape data to a long format

    I have ordinal variables defined as strongly agree, agree, neutral, disagree, and strongly disagree. I would like to reshape to a long format so that I can use clogit in my analysis. I tried to reshape but Stata tells me that some variables are not found and some of them turn up without values labels. I have used reshape long several times with no problem. Here is my sample dataset and code. Thank you in advance for your help.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float id long(used pusefproduct pusefsave pusefcontrol pusefuseful puseffind peaseeasy peaseclear peaseshopping peasecomplete peaseadapt ptrustworry ptrustsafe ptrustsites ptrustprivacy ptrusttrust)
     1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
     2 2 1 1 1 1 3 1 3 1 1 3 1 3 1 1 1
     3 1 4 4 4 1 4 1 1 1 4 4 1 1 3 3 3
     4 2 1 1 1 4 4 1 1 1 4 4 4 3 3 1 1
     5 2 4 4 4 4 4 4 4 4 4 4 4 1 1 1 1
     6 2 1 1 1 1 1 4 4 4 4 4 1 1 1 1 1
     7 2 1 1 1 1 1 4 4 4 4 4 1 1 1 1 1
     8 2 4 4 1 4 4 1 1 4 4 4 4 3 1 4 4
     9 2 3 1 1 1 4 1 3 1 1 1 3 5 1 3 3
    10 2 1 1 4 4 1 1 3 3 1 4 3 3 1 3 1
    11 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    12 2 1 1 1 1 1 1 3 3 1 1 3 3 1 1 3
    13 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    14 2 3 4 1 1 1 4 4 1 1 4 3 3 3 3 3
    15 2 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3
    16 1 2 2 2 2 2 2 1 1 2 4 2 2 2 2 2
    17 2 1 1 1 1 1 4 4 4 4 4 1 1 1 1 1
    18 2 4 4 4 4 1 4 1 3 4 4 1 1 1 4 4
    19 2 4 4 4 4 4 4 4 4 4 4 1 1 1 1 1
    20 2 4 4 4 1 4 4 4 3 4 1 4 4 4 4 4
    end
    label values used used_
    label def used_ 1 "No", modify
    label def used_ 2 "Yes", modify
    label values pusefproduct pusefproduct_
    label def pusefproduct_ 1 "Agree", modify
    label def pusefproduct_ 2 "Disagree", modify
    label def pusefproduct_ 3 "Neutral", modify
    label def pusefproduct_ 4 "Strongly Agree", modify
    label values pusefsave pusefsave_
    label def pusefsave_ 1 "Agree", modify
    label def pusefsave_ 2 "Disagree", modify
    label def pusefsave_ 4 "Strongly Agree", modify
    label values pusefcontrol pusefcontrol_
    label def pusefcontrol_ 1 "Agree", modify
    label def pusefcontrol_ 2 "Disagree", modify
    label def pusefcontrol_ 4 "Strongly Agree", modify
    label values pusefuseful pusefuseful_
    label def pusefuseful_ 1 "Agree", modify
    label def pusefuseful_ 2 "Disagree", modify
    label def pusefuseful_ 4 "Strongly Agree", modify
    label values puseffind puseffind_
    label def puseffind_ 1 "Agree", modify
    label def puseffind_ 2 "Disagree", modify
    label def puseffind_ 3 "Neutral", modify
    label def puseffind_ 4 "Strongly Agree", modify
    label values peaseeasy peaseeasy_
    label def peaseeasy_ 1 "Agree", modify
    label def peaseeasy_ 2 "Disagree", modify
    label def peaseeasy_ 4 "Strongly Agree", modify
    label values peaseclear peaseclear_
    label def peaseclear_ 1 "Agree", modify
    label def peaseclear_ 3 "Neutral", modify
    label def peaseclear_ 4 "Strongly Agree", modify
    label values peaseshopping peaseshopping_
    label def peaseshopping_ 1 "Agree", modify
    label def peaseshopping_ 3 "Neutral", modify
    label def peaseshopping_ 4 "Strongly Agree", modify
    label values peasecomplete peasecomplete_
    label def peasecomplete_ 1 "Agree", modify
    label def peasecomplete_ 2 "Disagree", modify
    label def peasecomplete_ 4 "Strongly Agree", modify
    label values peaseadapt peaseadapt_
    label def peaseadapt_ 1 "Agree", modify
    label def peaseadapt_ 3 "Neutral", modify
    label def peaseadapt_ 4 "Strongly Agree", modify
    label values ptrustworry ptrustworry_
    label def ptrustworry_ 1 "Agree", modify
    label def ptrustworry_ 2 "Disagree", modify
    label def ptrustworry_ 3 "Neutral", modify
    label def ptrustworry_ 4 "Strongly Agree", modify
    label values ptrustsafe ptrustsafe_
    label def ptrustsafe_ 1 "Agree", modify
    label def ptrustsafe_ 2 "Disagree", modify
    label def ptrustsafe_ 3 "Neutral", modify
    label def ptrustsafe_ 4 "Strongly Agree", modify
    label def ptrustsafe_ 5 "Strongly Desagree", modify
    label values ptrustsites ptrustsites_
    label def ptrustsites_ 1 "Agree", modify
    label def ptrustsites_ 2 "Disagree", modify
    label def ptrustsites_ 3 "Neutral", modify
    label def ptrustsites_ 4 "Strongly Agree", modify
    label values ptrustprivacy ptrustprivacy_
    label def ptrustprivacy_ 1 "Agree", modify
    label def ptrustprivacy_ 2 "Disagree", modify
    label def ptrustprivacy_ 3 "Neutral", modify
    label def ptrustprivacy_ 4 "Strongly Agree", modify 
    label values ptrusttrust ptrusttrust_
    label def ptrusttrust_ 1 "Agree", modify
    label def ptrusttrust_ 2 "Disagree", modify
    label def ptrusttrust_ 3 "Neutral", modify
    label def ptrusttrust_ 4 "Strongly Agree", modify
    reshape long pusef pease ptrust, i(id) j(group) string

  • #2
    Your command is legal and works.

    reshape is just telling you that not all prefix and suffix combinations are found among the variable names you gave.

    Code:
    adapt clear complete control easy find privacy product safe save shopping sites trust useful worry
    are the suffixes and

    Code:
    pusef pease ptrust
    are the prefixes. So reshape is on the look out for 3 x 15 = 45 variables to reshape and doesn't find them all.

    On your 5 point scales, so far as I can see you only need one set of value labels, say


    Code:
    label def grade 1 "Agree", modify
    label def grade 2 "Disagree", modify
    label def grade 3 "Neutral", modify
    label def grade 4 "Strongly Agree", modify
    label def grade 5 "Strongly Disagree", modify
    Note the typo correction to Desagree.
    Last edited by Nick Cox; 19 Aug 2023, 09:47.

    Comment


    • #3
      In fact the endorsement in #2 is quite wrong. Those labels result from a default encode order that is alphabetical. The order should surely run from Strongly agree to Strongly disagree and you need to define value labels before you encode.

      Comment


      • #4
        Thank you

        Comment

        Working...
        X