Announcement

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

  • Reshaping only one column

    Hi all, sorry for my 3rd reshape/xpose question of late, but I have a new (though similar) issue that I can't seem to solve.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str10 var double(b_all se_all b_most se_most b_never se_never)
    "white"        .3 .02  .43 .02 .52 .02
    "black"       .43 .03  .35 .03 .25 .02
    "hisp"        .11 .02  .09 .02  .1 .01
    "age"        14.3 .56 14.8  .5  15 .54
    "female"       .5 .01   .5 .01 .52 .01
    "test_score" 56.7 2.2   58 2.4  48 2.4
    end

    Essentially I want to tuck the SEs underneath the means in a new row, for each var, so it would produce a data frame where there's just 4 columns: "var", "all", "most", "never", and then each var has the mean and the SE in consecutive rows. Is it possible to basically just reshape only on the "se_" columns here?

    I tried:

    Code:
    reshape long se_, i(var) j(vble) string
    But that doesn't get quite what I want--it keeps one se column while creating new rows per each vble.

  • #2
    Perhaps
    Code:
    reshape long @all @most @never, i(var) j(param) string
    Code:
    . list, clean
    
                  var   param    all   most   never  
      1.          age      b_   14.3   14.8      15  
      2.          age     se_    .56     .5     .54  
      3.        black      b_    .43    .35     .25  
      4.        black     se_    .03    .03     .02  
      5.       female      b_     .5     .5     .52  
      6.       female     se_    .01    .01     .01  
      7.         hisp      b_    .11    .09      .1  
      8.         hisp     se_    .02    .02     .01  
      9.   test_score      b_   56.7     58      48  
     10.   test_score     se_    2.2    2.4     2.4  
     11.        white      b_     .3    .43     .52  
     12.        white     se_    .02    .02     .02
    Or perhaps
    Code:
    gen seq = _n
    reshape long @all @most @never, i(seq var) j(param) string
    if you want the rows in the order they were in initially.
    Last edited by William Lisowski; 07 Sep 2022, 10:26.

    Comment

    Working...
    X