Announcement

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

  • how do I generate a variable containing frequencies on two similar variables?

    Hello

    Im am new to STATA.
    I have a dataset that contains data from different surveys on similar categorical variables called gop_studsoc_sch and gop_studsoc_bgu. The variables use the same scale 1”high priority” to 6 “low priority”. I would like to collapse these variables into a single variable with frequency distribution. I have found a command stack that does exactly that:
    stack gop_studsoc_sch gop_studsoc_bgu, into (gop_studsoc_sch_bgu)

    But doing this I lose all the other variables in my dataset. Do I then need to save this new variable as a dataset and then merge it with the old dataset to keep the other variables in the dataset or is there an easier way?

    The data looks like this for the two variables:

    tabm gop_studsoc_sch gop_studsoc_bgu, transpose
    Values gop_studsoc_sch gop_studsoc_bgu Total
    1 1 5 6
    2 17 11 28
    3 30 36 66
    4 25 16 41
    5 16 12 28
    6 5 9 14
    Total 94 89 183
    Total is in short the variable (gop_studsoc_sch_bgu) I would like to create but keeping all other the variables in my dataset.

    Best regards
    Lars

  • #2
    tabm (tab_chi, SSC) that you have used (but not cited: see FAQ Advice #12) has an option replace to save its results to a new dataset.

    I don't understand what you expect a merge to achieve here.

    Comment

    Working...
    X