Announcement

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

  • Summary table with column names created from variable suffix

    Suppose the following data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(n_IM_ER_pos n_IM_ER_neut n_IM_ER_neg n_IM_EG_pos n_IM_EG_neut n_IM_EG_neg)
    0 1 0 0 0 0
    0 0 0 0 0 0
    0 0 2 0 0 0
    1 0 0 0 0 0
    0 0 0 0 0 0
    0 0 0 1 0 0
    2 0 3 0 0 0
    0 0 0 0 0 0
    0 1 0 0 0 0
    0 0 0 0 0 0
    end

    Each variable name has either the suffix _pos, _neut or _neg assigned to it. My goal is to create a table of sums consisting of the three columns "Pos.", "Neut." and "Neg." which I would like to export to word.
    Each row should contain the respective sum for each of the three columns.

    This screenshot is supposed to illustrate what the ending result should look like:

    Click image for larger version

Name:	Example.PNG
Views:	1
Size:	12.7 KB
ID:	1703094

    For example:
    Cell B15 contains the sum of the variable n_IM_ER_pos
    Cell C15 contains the sum of the variable n_IM_ER_neu
    Cell D15 contains the sum of the variable n_IM_ER_neg

    I haven't got any further with this issue as I am struggling to create the desired columns from the variable names suffix.

    Any help is much appreciated
    Thank you

  • #2
    Code:
    collapse (sum) *
    gen id=1
    ren *_neg neg_*
    ren *_pos pos_*
    ren *_neut neut_*
    reshape long neg_ pos_ neut_, i(id) j(type) str
    ren *_ *

    Comment

    Working...
    X