Announcement

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

  • how to count numbers of households expose to a specific shock?

    Dear all,

    I need your help in the following issue in coding my data.

    I have a data set for a year for households with exposure to different types of shocks. Uniquely Identified level is household => shock_id => shock_month => shock_year
    One household can expose to more than one shocks.
    Hence the same shock can be reported two or three times as it happens at different month/year.

    I would like to know:

    1) how many households (or percentage of households) exposure to a specific type of shock, i.e. floods, droughts....regardless of month or year?

    2) How many shocks a households have experienced regardless of month or year?

    Since shock_id is not uniquely identified, if I use "by" and "count" command, one shock can be counted two times for a household.

    Can you suggest me another way to answer my two questions?

    Much thanks!


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long(hhid2014 shock_id) byte shock_month int shock_year
     16  3  5 2014
     16  3  6 2013
     20  3  8 2013
     20  8  5 2013
     31  3 12 2013
     31  7  8 2013
     39  6  5 2013
     39  8  8 2013
     43 10 10 2013
     43 11  5 2014
     43 12  4 2013
     46  6  8 2013
     46  8  4 2014
     60  3  3 2014
     60  8  4 2014
     61  3  6 2014
     61  3  7 2012
     63  3  5 2014
     63  9  4 2014
     67  3  1 2014
     67 11 11 2013
     69  3  7 2013
     69  8 10 2013
     70  3  8 2012
     70  8  2 2014
     74  3  2 2014
     74  8  6 2013
     77  3 10 2013
     77  8  6 2014
     82  3  1 2014
     82  8  6 2014
     84  3  3 2014
     84  8  9 2013
     87  8 11 2012
     87 15 10 2012
     91  8  3 2014
     91  9  3 2014
     95  3  4 2014
     95  3  5 2014
     95  3  6 2014
     97  3  7 2013
     97  8 12 2013
     99  3 12 2013
     99  8  5 2014
    101  7  2 2014
    101  8  5 2014
    101 16  5 2014
    108  3  5 2014
    108  6  6 2013
    111  3  4 2014
    111  5  7 2013
    111  6  9 2013
    112  5  7 2013
    112  6  4 2014
    116  3  8 2013
    116  3 12 2013
    119  3 12 2013
    119  5  4 2013
    119  6  7 2013
    120  3  1 2014
    120  4  5 2013
    120  4  8 2012
    121  6  4 2013
    121  6  4 2014
    121  6  7 2012
    122  3  6 2014
    122  8  3 2013
    122  8  3 2014
    123  8  9 2013
    123 14 12 2013
    124  3  7 2012
    124  6  5 2013
    125  3  5 2014
    125  8  5 2013
    125  8  5 2014
    126  8  3 2013
    126  8  3 2014
    126  8 10 2013
    136  3  7 2013
    136  9 12 2013
    144  3  4 2014
    144  9 12 2013
    153  3  2 2014
    153  8 12 2013
    174  8  8 2013
    174  9 12 2013
    177 10  9 2013
    177 11  5 2013
    177 12 12 2013
    180  3  9 2013
    180  6  2 2013
    180  8 11 2013
    183  8  3 2014
    183  9  8 2013
    187  6  3 2014
    187  8  9 2013
    187  9  2 2014
    188  6  3 2014
    188  7 12 2013
    188  9  2 2014
    190  7  1 2014
    190  8  4 2014
    193  7  1 2014
    193  8  3 2014
    194  7  1 2014
    194  8  2 2014
    194  9  3 2014
    195  6  5 2013
    195  8  9 2013
    195  9  2 2014
    196  6  3 2014
    196  8  3 2014
    196  9  2 2014
    197  6  3 2014
    197  7 12 2013
    197  8  3 2014
    198  6  3 2014
    198  7 12 2013
    198  8  2 2014
    199  6  4 2014
    199  8  9 2013
    199  9 12 2013
    200  7 12 2013
    200  8  9 2013
    200  9 12 2013
    202  6  3 2014
    202  8  8 2013
    202  9  4 2014
    203  6  3 2014
    203  8  9 2013
    203  9 12 2013
    206  6  3 2013
    206  8  4 2014
    208  7 12 2013
    208  9  3 2014
    209  7  1 2014
    209  8  5 2014
    210  6  8 2013
    210  7 12 2013
    210  9 12 2013
    211  7  1 2014
    211  8  1 2014
    214  6  3 2014
    214  7  1 2014
    214  8  2 2014
    216  6  3 2014
    216  7 12 2013
    216  9 10 2013
    217  6  8 2013
    217  8  7 2014
    218  6  3 2014
    218  8  9 2013
    218  9  2 2014
    219  6  3 2014
    219  7 12 2013
    219  9 12 2013
    220  7 12 2013
    220  8  3 2014
    220  9 12 2013
    221  6  4 2014
    221  8  9 2013
    221  9  2 2014
    223  3  5 2013
    223  8  9 2013
    223  9 12 2013
    225  7  1 2014
    225  8  4 2014
    226  7 12 2013
    226  8  3 2014
    227  7  1 2014
    227  8  4 2014
    228  6  3 2014
    228  7 12 2013
    228  9  2 2014
    229  6  3 2014
    229  7 12 2013
    229  9 12 2013
    230  9  2 2014
    230 12  2 2013
    231  6  2 2014
    231  8  8 2013
    235  6  5 2014
    235  8  4 2014
    237  6  4 2014
    237  8 12 2013
    239  6  4 2014
    239  8  6 2013
    241  6  5 2014
    241  8  4 2014
    242  6  4 2014
    242  9 12 2013
    244  6  4 2014
    244  7 11 2013
    244  8 10 2013
    245  6  3 2014
    245  6 12 2013
    245  9  4 2014
    247  6  3 2014
    247  8  9 2013
    247  9 12 2013
    251  6  4 2014
    251  7 11 2013
    251  8  2 2014
    252  7  2 2013
    252  8  9 2013
    252  9 12 2013
    254  6  4 2014
    254  8  9 2013
    255  6  3 2014
    255  7  7 2013
    255  8 12 2013
    257  6  2 2014
    257  8  3 2014
    260  6  8 2013
    260  8  2 2014
    263  6  5 2014
    263  8  4 2014
    264  3  3 2014
    264  6  5 2014
    264  8  1 2014
    265  6  8 2013
    265  8  3 2014
    266  8  8 2013
    266  9  1 2014
    267  7  7 2013
    267  8  9 2013
    267  9 12 2013
    268  6  3 2014
    268  8  7 2013
    268  9  3 2014
    270  6  3 2014
    270  8  9 2013
    270  9 12 2013
    271  6  3 2014
    271  7  7 2013
    271  9 12 2013
    272  6  3 2014
    272  8 12 2013
    272  9  2 2014
    273  6  8 2013
    273  8  2 2014
    273  8  4 2014
    274  6  2 2014
    274  9  2 2014
    275  6  8 2013
    275  8  2 2014
    276  6  3 2014
    276  7  8 2014
    276  9  3 2014
    278  6  3 2014
    278  8  9 2013
    278  9 12 2013
    279  6  5 2014
    279  8  3 2014
    281  6  3 2014
    281  9 11 2013
    282  6  3 2014
    282  7  8 2013
    282  8 12 2013
    283  6  2 2014
    283  7  3 2013
    283  8 10 2013
    284  6  3 2014
    284 12 10 2013
    288  6  3 2014
    288  7  8 2013
    288  9 12 2013
    289  3 10 2013
    289  6  4 2013
    290  6  4 2014
    290  8  3 2014
    291  6  2 2014
    291  8  1 2013
    291  9  3 2014
    292  6  3 2014
    292  7  7 2013
    292  8 12 2013
    294  6  4 2013
    294  7 11 2013
    294  8  2 2013
    295  6  3 2014
    295  9  3 2014
    296  6  5 2014
    296  8  4 2014
    298  6  3 2014
    298  8  9 2013
    298  9 12 2013
    299  6 11 2013
    299  8  3 2014
    299  9  4 2013
    300  6  3 2014
    300  8  2 2013
    300  9  2 2014
    301  6  5 2014
    301  8  3 2014
    303  6  3 2014
    303  8  2 2014
    304  6 11 2013
    304  8  4 2014
    304  9  4 2014
    305  6  3 2014
    305  8 12 2013
    305 11 12 2013
    307  6  4 2014
    307  8 12 2013
    308  6  3 2014
    308  7 12 2013
    308  9 12 2013
    309  6  5 2014
    309  8  3 2014
    310  6  3 2014
    310  8  9 2013
    310  9 12 2013
    312  6  3 2014
    312  8  3 2014
    312  9 12 2013
    313  6  3 2014
    313  8  9 2013
    313  9  2 2014
    315  6  5 2014
    315  8  4 2014
    316  6  3 2014
    316  9  2 2014
    317  7 12 2013
    317  8  9 2013
    317  9  2 2014
    318  6  3 2014
    318  8  9 2013
    318  9 12 2013
    323  6  5 2014
    323  8  4 2013
    325  6  3 2014
    325  8 10 2013
    325  9  3 2014
    326  6  1 2014
    326  9  3 2014
    327  6  3 2014
    327  8  4 2014
    328  6  4 2014
    328  8  3 2011
    330  8  3 2014
    330  9 12 2013
    336  8 12 2013
    336  9  3 2014
    339  5  7 2013
    339  8  4 2014
    339  9  3 2014
    340 10 99 2012
    340 11 99 2013
    340 12 99 2013
    341  8  2 2013
    341  9  1 2013
    341 10  4 2013
    342  6  3 2014
    342  7  7 2013
    342  8  5 2014
    343  6  5 2014
    343  8  8 2013
    346  5  7 2013
    346  8  4 2014
    349  6  4 2014
    349  9 11 2013
    350  5  7 2013
    350  7  9 2013
    350  8 12 2013
    351  5  7 2013
    351  7 12 2013
    351  8 12 2013
    356  7  7 2013
    356  8 12 2013
    359  6  3 2014
    359  8  3 2014
    359  9  2 2014
    360  7 12 2013
    360  9  3 2014
    361  7  7 2013
    361  8 12 2013
    364  6  3 2014
    364  7 12 2013
    365  6  3 2014
    365  7 12 2013
    365  9  2 2014
    373  5  7 2013
    373  6  1 2014
    373  7  4 2014
    374  7  7 2013
    374  8 12 2013
    376  7  1 2014
    376  8  4 2014
    377  7  1 2014
    377  8  4 2014
    378  6  3 2014
    378  7 12 2013
    378  9  2 2014
    382  7 12 2013
    382  8 11 2013
    382  9  3 2014
    383  6  3 2014
    383  8  8 2013
    384  7 12 2013
    384  8 12 2013
    389  6  3 2014
    389  7 12 2013
    389  9  2 2014
    391  6  9 2013
    391  8  3 2014
    392  6  2 2014
    392  7 12 2013
    392  8  3 2014
    393  6  4 2014
    393  8 11 2013
    396  8  8 2013
    396  9  3 2014
    397  8  1 2014
    397  9  3 2014
    399  6  4 2014
    399 16  3 2014
    404  6  4 2013
    404  8  2 2014
    409  8  3 2014
    409  9 12 2013
    411  6  5 2014
    411  8  3 2014
    413  6  5 2013
    413  8  5 2014
    415  5  8 2013
    415  6  3 2014
    415  9  2 2013
    416  6  3 2014
    416  8  9 2013
    416  9 12 2013
    417  6  3 2014
    417  8  8 2013
    417  9 12 2013
    418  6  3 2014
    418  6  7 2013
    418  9 12 2013
    419  3  2 2014
    419  3  4 2013
    419  3  8 2013
    423  8  1 2014
    423  8  8 2013
    434  3  2 2014
    434  6 10 2013
    443  3 10 2013
    443  6  6 2014
    443  6 10 2013
    446  8  6 2014
    446  8  8 2013
    453  7  5 2013
    453 16 12 2013
    455  3  9 2013
    455  8  7 2013
    458  8  7 2013
    458  8 10 2013
    474  8  6 2014
    474  8 10 2013
    480  8  4 2013
    480  8  4 2014
    485  8  4 2013
    485  8  4 2014
    488  8  8 2013
    488 12 12 2013
    489  5  8 2013
    489  8  5 2013
    489 12 11 2013
    491  5  9 2013
    491  6  4 2013
    491  9 11 2013
    492  6  5 2013
    492  8 12 2013
    493  6  4 2014
    493 12 12 2013
    497  7  8 2013
    497  8  4 2013
    498  7  7 2013
    498  8 10 2013
    500  7  8 2013
    500  8 11 2013
    502  5  8 2013
    502  6  5 2013
    502 12 11 2013
    503  7  9 2013
    503  8 11 2013
    505  6 11 2013
    505  8  2 2014
    509  5  8 2013
    509  8  4 2013
    509  9 11 2013
    511  7  7 2013
    511  8 11 2013
    513  7  7 2013
    513  8 10 2013
    514  6 10 2013
    514  8  2 2014
    515  6  5 2013
    515  8 10 2013
    516  7  8 2013
    516  8 10 2013
    519  3  9 2012
    519  7  8 2013
    519  8 12 2013
    520  6 11 2013
    520  8  2 2014
    522  7 12 2013
    522  8  2 2013
    523  6 10 2013
    523  8  2 2014
    524  3  8 2013
    524  8  3 2013
    524 12 12 2013
    525  7  7 2013
    525  8 10 2013
    527  6 10 2013
    527  8  2 2013
    531  7  8 2013
    531  8 11 2013
    532  5  7 2013
    532  6  4 2013
    532  9 11 2013
    533  7  6 2013
    533  8 10 2013
    534  6  8 2013
    534  8 12 2013
    538  6  5 2013
    538  8 10 2013
    539  7  8 2013
    539  8 11 2012
    540  6  1 2014
    540  8 10 2013
    541  7  7 2013
    541  8 12 2013
    543  6  1 2014
    543  7  8 2013
    543  8 12 2013
    546  5  8 2013
    546  8 11 2013
    548  4  6 2014
    548  7  7 2013
    548  8 11 2013
    550  6 12 2013
    550  7  7 2013
    550  8 12 2013
    551  6  3 2014
    551  8  2 2014
    553  7  7 2013
    553  8 12 2013
    556  6  4 2014
    556  8  1 2014
    557  5  8 2013
    557  9 11 2013
    558  5  8 2013
    558  6  4 2013
    558 12 12 2013
    559  5  8 2013
    559  6  4 2013
    559  8 11 2013
    560  6 11 2013
    560  8  1 2014
    561  7  7 2013
    561  8 10 2013
    563  6 10 2013
    563  8  3 2014
    564  6  5 2013
    564 12 12 2013
    567  5  8 2013
    567  6  5 2013
    568  3  9 2013
    568  7  7 2013
    569  7  7 2013
    569  8 12 2012
    570  3 10 2013
    570  7  7 2013
    570  8  9 2013
    571  7  7 2013
    571  8 11 2013
    572  7  8 2013
    572  8 10 2013
    573  6  4 2013
    573 12 12 2013
    574  5  8 2013
    574  6  4 2013
    574  8 12 2013
    575  5  9 2013
    575  8 12 2013
    576  7  8 2013
    576  8  5 2013
    577  6 10 2013
    577  8  2 2014
    579  3  4 2013
    579  7  8 2013
    580  6 11 2013
    580  8  2 2014
    581  6 12 2013
    581  7  7 2013
    581  8  5 2013
    583  7  7 2013
    583  8 12 2013
    584  5  8 2013
    584  8  1 2014
    584 12  3 2014
    585  8  9 2013
    585 10  2 2014
    587  7  7 2013
    587  8 11 2013
    589  5  8 2013
    589  6 10 2013
    589  8  3 2013
    592  6 10 2013
    592  7  7 2013
    596  8  6 2013
    596  9 11 2013
    598  6 11 2013
    598  8  2 2014
    599  6 10 2013
    599  8  9 2013
    599  9 10 2013
    600  6  5 2013
    600  8  8 2013
    601 10 12 2013
    601 12 11 2013
    601 13  4 2013
    602  8 11 2013
    602  9 11 2013
    603  3 11 2013
    603 10 12 2013
    603 12 12 2013
    614  5  8 2013
    614 12 12 2013
    617  6 99 2013
    617  7 99 2013
    618  3  5 2013
    618  7  7 2013
    619  3  9 2013
    619  7  8 2012
    619  8  2 2014
    620  7  6 2013
    620  8  2 2014
    627  5  7 2013
    627  8 12 2013
    628  6  6 2013
    628  9 12 2013
    631  6 10 2013
    631  8  2 2014
    642  6 11 2013
    642  8  2 2014
    645  8  2 2014
    645  9  1 2014
    646  6 10 2013
    646  8  1 2014
    649  6 10 2013
    649  8  2 2014
    654  6 10 2013
    654  8  1 2014
    658  6 12 2012
    658  7  7 2013
    658  8  4 2013
    659  6  4 2013
    659  8  9 2013
    662  5  8 2013
    662  6  4 2013
    662 11 12 2013
    665  5  8 2013
    665  6  4 2013
    668  6 10 2013
    668  8  2 2014
    669  6 11 2013
    669  8  1 2014
    673  7  1 2013
    673  8  7 2012
    674  6 10 2013
    674  8 11 2013
    676  7  7 2013
    676  8 12 2012
    678  7  7 2013
    678  8 12 2013
    681  7  8 2013
    681  8  8 2012
    686  5  8 2013
    686  6  6 2013
    686  8 12 2013
    688  3  4 2013
    688  5  7 2013
    689  5  8 2013
    689  6  4 2013
    689 12 10 2013
    690  7  7 2013
    690  8  1 2013
    691  6 10 2013
    691  8  2 2014
    693  5  8 2013
    693  8 11 2013
    696  6  6 2013
    696  8 12 2013
    697  6  6 2013
    697  8 12 2013
    698  5  8 2013
    698  9 12 2013
    699  3  1 2013
    699  8  9 2013
    end
    label values shock_id p44q2a_new
    label def p44q2a_new 3 "11.serious illness of hh member", modify
    label def p44q2a_new 4 "12.another shocks", modify
    label def p44q2a_new 5 "1a.floods", modify
    label def p44q2a_new 6 "1b.drouhgts", modify
    label def p44q2a_new 7 "1c.typhoons", modify
    label def p44q2a_new 8 "2.pest infestation and crop diseases", modify
    label def p44q2a_new 9 "3.avian flu", modify
    label def p44q2a_new 10 "4a.change in crop price", modify
    label def p44q2a_new 11 "4b.change in price of inputs", modify
    label def p44q2a_new 12 "5.foods and essentials price change", modify
    label def p44q2a_new 13 "6.unemployment", modify
    label def p44q2a_new 14 "7.unsuccessful investment", modify
    label def p44q2a_new 15 "8.loss of land", modify
    label def p44q2a_new 16 "9.crime(robbery)", modify
    label values shock_month p44Q2B_
    label def p44Q2B_ 99 "don't remember", modify










  • #2
    I find it easy to use contract, which 'destroys' the original dataset but gives you a frequency count variable. You can always merge into the original dataset on household id. It's not entirely clear to me how you want to handle multiple shocks, but here's one approach which you can tweak.

    Code:
    contract hhid2014 shock_id,  freq(shocks_occured)
    
    // 1) how many households (or percentage of households) exposure to a specific type of shock, i.e. floods, droughts....regardless of month or year?
    egen count_hh_exposed  = count(shock_id), by(shock_id)
    
    // 2) How many shocks a households have experienced regardless of month or year?
    egen shocks_per_hh = count(shock_id), by(hhid2014)
    egen shocks_per_hh = count(shock_id), by(hhid2014) can also be modified to
    Code:
    egen shocks_per_hh = total(shocks_occured), by(hhid2014)
    if that's what you were after (I wasn't sure). Hope this helps.
    Last edited by Justin Niakamal; 01 Dec 2020, 12:12.

    Comment


    • #3
      Hi Justin,

      Thank you for your reply and suggested command!

      However, for question 1, I mean to know how many households expose to floods? how many household expose to droughts? and for other specific shocks separately.

      As for question 2, I think the command still count the same shock two times. For example, a household experienced droughts (2 times/year) and typhoon (1 time). So the numbers of shocks I would like to know is only two (droughts and typhoon). But because the droughts happened two times, so for the command, it will count as 3 shocks for that households.
      Last edited by Trang Thu Vu; 01 Dec 2020, 19:20.

      Comment

      Working...
      X