Announcement

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

  • R Loop To get Survey Weighted Counts

    Code:
    input person status group angle weight
    1 2 3 30 152
    2 3 2 29 176
    3 2 6 20 146
    4 3 6 30 194
    5 3 4 21 123
    6 2 2 23 169
    7 1 3 29 118
    8 3 6 30 165
    9 3 5 27 130
    10 2 1 22 196
    11 1 4 24 147
    12 1 6 21 172
    13 2 2 26 179
    14 1 5 26 142
    15 3 6 23 170
    16 2 1 22 134
    17 3 2 26 138
    18 1 2 30 129
    19 2 5 29 194
    20 3 1 20 129
    21 1 5 26 190
    22 2 3 23 195
    23 1 2 24 105
    24 3 3 30 136
    25 3 5 23 157
    26 1 1 22 188
    27 3 4 26 134
    28 1 5 29 177
    29 2 3 27 125
    30 1 3 28 185
    31 1 1 29 103
    32 2 3 26 175
    33 2 3 21 151
    34 1 2 26 183
    35 2 5 22 135
    36 2 2 28 163
    37 1 3 28 112
    38 1 6 22 102
    39 1 2 30 170
    40 1 6 30 199
    41 2 1 26 161
    42 2 6 21 183
    43 1 1 30 115
    44 2 6 28 121
    45 2 2 24 140
    46 1 4 30 106
    47 1 3 25 139
    48 3 3 24 115
    49 2 5 24 160
    50 2 2 23 185
    51 2 1 20 185
    52 2 2 21 145
    53 3 5 27 148
    54 3 5 22 108
    55 1 2 23 192
    56 3 5 22 153
    57 1 2 20 178
    58 1 2 21 128
    59 1 4 29 118
    60 1 6 26 102
    61 3 2 20 181
    62 1 4 30 197
    63 3 2 26 147
    64 1 5 26 110
    65 2 5 26 132
    66 3 2 23 132
    67 1 6 30 147
    68 2 5 23 188
    69 1 6 27 194
    70 2 6 28 119
    71 3 2 25 108
    72 3 6 28 126
    73 3 2 28 121
    74 2 2 23 129
    75 3 3 25 121
    76 3 1 23 123
    77 2 4 26 107
    78 1 1 23 149
    79 1 6 26 160
    80 1 4 21 160
    81 2 4 30 147
    82 2 4 21 165
    83 3 1 29 109
    84 1 1 21 181
    85 2 3 27 100
    86 1 2 27 172
    87 3 3 26 120
    88 2 4 26 126
    89 2 1 30 163
    90 2 3 30 135
    91 1 6 22 196
    92 1 1 28 187
    93 3 2 29 169
    94 2 1 26 132
    95 3 1 25 115
    96 3 2 28 164
    97 3 6 22 110
    98 2 6 20 149
    99 1 5 28 161
    end
    
    
    quietly forvalues i = 20/30 & j = 1/6 { 
        gen x =  status [w=weight] if angle== `i' & group= `j', detail  
     }
    I have data at one time point. I want to apply the sample weights "weight" to the "status" variable to get weighted counts of status for each combination of "angle" and "group". There are 11 angles and 6 groups and thus I basically want a new data set that is 66 rows and has 3 columns--for each status. Thank you

  • #2
    Thanks for the data example. This seems confused:

    1. If you want R code for this, Statalist is not the place to ask.

    2. The code following your data example is a series of wild guesses. There are several reasons why it won't do what I think you want, but I will not detail them.

    This code may help:

    Code:
    contract angle group status [fw=weight]
    replace _freq = 0 if _freq == . 
    reshape wide _freq, i(group angle) j(status)
    sort angle group
    list angle group _freq* , sepby(angle)

    Comment

    Working...
    X