Announcement

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

  • Generating count variable

    I have a data set of attitudes on immigration. I want to derive estimates of attitudes by state and then to use the estimates only for states with sample sizes >= 60.
    I wrote:

    . egen ssize = count(statesamp)

    . oneway ssize state,tab

    | Summary of ssize
    State | Mean Std. Dev. Freq.
    ------------+------------------------------------
    me | 3242 0 9
    nh | 3242 0 11
    vt | 3242 0 3
    ma | 3242 0 64
    ri | 3242 0 12
    ct | 3242 0 32
    ny | 3242 0 187
    nj | 3242 0 81
    pa | 3242 0 133
    oh | 3242 0 113
    in | 3242 0 56
    il | 3242 0 113
    mi | 3242 0 83
    wi | 3242 0 62
    mn | 3242 0 46
    ia | 3242 0 23
    mo | 3242 0 38
    nd | 3242 0 7
    sd | 3242 0 8
    ne | 3242 0 23
    ks | 3242 0 24
    de | 3242 0 10
    md | 3242 0 59
    dc | 3242 0 4
    va | 3242 0 88
    wv | 3242 0 11
    nc | 3242 0 120
    sc | 3242 0 48
    ga | 3242 0 100
    fl | 3242 0 219
    ky | 3242 0 39
    tn | 3242 0 47
    al | 3242 0 48
    ms | 3242 0 30
    ar | 3242 0 26
    la | 3242 0 40
    ok | 3242 0 40
    tx | 3242 0 289
    mt | 3242 0 12
    id | 3242 0 13
    wy | 3242 0 3
    co | 3242 0 62
    nm | 3242 0 26
    az | 3242 0 70
    ut | 3242 0 33
    nv | 3242 0 37
    wa | 3242 0 67
    or | 3242 0 42
    ca | 3242 0 499
    ak | 3242 0 10
    hi | 3242 0 22
    ------------+------------------------------------

    and then:

    . fsum admitrefugeesallies pid7 ideology muslim catholic jewish ssize

    Variable | N Mean SD Min Max
    ---------------------+---------------------------------------------
    admitrefugeesallies | 51 0.78 0.10 0.59 1.00
    pid7 | 51 2.10 0.19 1.74 2.67
    ideology | 51 4.05 0.43 2.33 5.00
    muslim | 51 0.00 0.01 0.00 0.04
    catholic | 51 0.17 0.10 0.00 0.45
    jewish | 51 0.01 0.02 0.00 0.10
    ssize | 51 3242.00 0.00 3242.00 3242.00

    I have tried to obtain a measure of sample sizes for states, using egen count and r(state) but nothing seems to work. Any help in obtaining a measure of sample size for states would be appreciated.

  • #2
    Code:
    by state, sort: gen ssize = _N
    What your command, -egen ssize = count(statesamp)- does is just create a variable which contains, in every observation, the number of observations that contain a non-missing value in the variable statesamp. On the assumption that statesamp is never missing, equivalently, that command simply counts the number of observations in the data set and saves the results in every observation for the new variable ssize.

    Comment


    • #3
      Thanks much!

      Comment

      Working...
      X