Announcement

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

  • Creation of new variable from tertile mean values

    Dear people,

    Could you please help me on the following issue ?

    I have a continuous variable describing the mental health score, I created tertile from this continuous variable, and tabstat to have the mean in each tertile. Now I would like to create a new variable of these tertile mean. Is that possible ? I tried to do all combination, without success.

    Here is my data look like :
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float fatherK2
     0
     2
     1
    25
     0
     1
     0
     2
     4
     3
     1
     3
     3
     0
     2
     0
     6
     1
     2
     3
     0
    end
    label values fatherK2 ght
    label def ght 25 "No father at home", modify
    Code:
    xtile fatherK2_T3=fatherK2, nq(3)
    Code:
    tabstat fatherK2, stat (mean sd n) by (fatherK2_T3)
    What I want is to extract the means from tabstat and create a new variable with it, such as the following example table. Because afterwards I need to do a linear regression.

    tertile mean
    1 xx
    2 xx
    3 xx

    Many thanks for your help
    Ginie

  • #2
    Code:
    collapse fatherK2, by(fatherK2_T3)
    See

    Code:
    help collapse

    Comment


    • #3
      Code:
      by fatherK2_T3, sort: egen wanted = mean(fatherK2)
      Added: Crossed with #2. The approach there will reduce the data set to a single observation for each tertile. The approach here maintains the original number of observations and creates a variable equal to the mean of the father_K2 in that tertile.

      Comment


      • #4
        Thank you so much that is exactly what I needed.

        Comment

        Working...
        X