Announcement

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

  • Long transformation problem

    Hello together,
    i have a problem with my Stata code.
    I have a variable, where people were supposed to tell, with whom they talk about sexuality (mother, father, friends, and so on). The data didnt catch the multiple mentions, and when I tabulate the variable, I just get 68 total observations (there were 68 participants). I already have dummyvariables for every answering options, telling me whether each and every one of them got chosen or not.
    In order to work with it, I thought that I needed to long transform it (reshape long), but this doesnt solve the problem.

    So with the code "reshape long a001_, i(case) j(x)" I wanted to order the data according to the dummyvariables mentioned above (a001_01, a001_02, a001_03,...a001_12) but now it just multiplies the observations by 12.
    I also tried to create a new variable;

    (gen var1 = .
    replace var1 = 1 if a001_01 == "ausgewählt"
    replace var1 = 2 if a001_02 == "ausgewählt"
    replace var1 = 3 if a001_03 == "ausgewählt"
    replace var1 = 4 if a001_04 == "ausgewählt"
    replace var1 = 5 if a001_05 == "ausgewählt"
    replace var1 = 6 if a001_06 == "ausgewählt"
    replace var1 = 7 if a001_07 == "ausgewählt"
    replace var1 = 8 if a001_08 == "ausgewählt"
    replace var1 = 9 if a001_09 == "ausgewählt"
    replace var1 = 10 if a001_10 == "ausgewählt"
    replace var1 = 11 if a001_11 == "ausgewählt"
    replace var1 = 12 if a001_12 == "ausgewählt")

    but it doesnt work either.


    As a last hope I tried to sum them up by using the code:
    egen var_sum = rowtotal(a001_01=="ausgewählt", a001_02=="ausgewählt", a001_03=="ausgewählt", a001_04=="ausgewählt", a001_05=="ausgewählt", a001_06=="ausgewählt", a001_07=="ausgewählt", a001_08=="ausgewählt", a001_09=="ausgewählt", a001_10=="ausgewählt", a001_11=="ausgewählt", a001_12=="ausgewählt")
    but this also wouldnt work.

    Has anyone a idea how i could account for the multiple mensions for this variable? I am really lost and cant find anything on the internet regarding that problem.
    Hopefully someone has an idea.

    Kind regards, Allegrio

  • #2
    Allegrio, hi.

    if you can provide us with a more concrete example, it will easier for us to help you out. Based on the description above, I have been unable to understand the problem sufficiently to come up with a solution.

    Comment


    • #3
      The row total you want can be got by

      Code:
      gen wanted = 0 
      
      foreach v of var a001_??  { 
            replace wanted = wanted + ( `v' == "ausgewählt") 
      }
      The last command in #1 fails because rowtotal() needs a list of variable names, and anything else is illegal.

      Comment

      Working...
      X