Announcement

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

  • generate variable

    Hello I need help with this please

    I have a ethnicity variable which take values SHANJO SHANJO LOZI SHANJO . I want to generate a variable share as

    share .075 .075 .025 .075


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float delid str21 ethnicity float shej
    30389 "SHANJO"         .075
    30389 "SHANJO"         .075
    30389 "LOZI"           .025
    30389 "SHANJO"         .075
    30393 "BEMBA"      .1627907
    30393 "MBUNDA"   .011627907
    30393 "TONGA"     .23255815
    30393 "LUVALE"   .023255814
    30393 "NDEBELE"  .011627907
    30393 "LOZI"       .1744186
    30393 "LOZI"       .1744186
    30393 "TUMBUKA"   .04651163
    30393 "TONGA"     .23255815
    30393 "LOZI"       .1744186
    30393 "BEMBA"      .1627907
    30393 "LALA"     .011627907
    30393 "KAONDE"   .023255814
    30393 "LOZI"       .1744186
    30393 "TONGA"     .23255815
    30393 "TOKA"     .023255814
    30393 "TONGA"     .23255815
    30393 "NSENGA"    .09302326
    30393 "TONGA"     .23255815
    30393 "LOZI"       .1744186
    30393 "BEMBA"      .1627907
    30393 "TUMBUKA"   .04651163
    30393 "NSENGA"    .09302326
    30393 "LUNDA"    .011627907
    30393 "ENGLISH"  .011627907
    30393 "ILA"      .023255814
    30393 "BEMBA"      .1627907
    30393 "TOKA"     .023255814
    30393 "BISA"     .023255814
    30393 "BISA"     .023255814
    30393 "TUMBUKA"   .04651163
    30393 "KAONDE"   .023255814
    30393 "TOKALEYA" .011627907
    30393 "NAMWANGA" .011627907
    30393 "BEMBA"      .1627907
    30393 "LOZI"       .1744186
    30393 "NGONI"    .023255814
    30393 "TONGA"     .23255815
    30393 "LOZI"       .1744186
    30393 "BEMBA"      .1627907
    30393 "BEMBA"      .1627907
    30393 "NGONI"    .023255814
    30393 "NSENGA"    .09302326
    30393 "LOZI"       .1744186
    30393 "BEMBA"      .1627907
    30393 "BEMBA"      .1627907
    30393 "LOZI"       .1744186
    30393 "BEMBA"      .1627907
    30393 "\NYANJA"  .011627907
    30393 "TUMBUKA"   .04651163
    30393 "NSENGA"    .09302326
    30393 "BEMBA"      .1627907
    30393 "TONGA"     .23255815
    30393 "LUVALE"   .023255814
    30393 "NSENGA"    .09302326
    30393 "NSENGA"    .09302326
    30393 "BEMBA"      .1627907
    30393 "LENJE"    .011627907
    30393 "BEMBA"      .1627907
    30393 "CHEWA"    .023255814
    30393 "CHOKWE"   .011627907
    30393 "NSENGA"    .09302326
    30393 "TONGA"     .23255815
    30393 "NSENGA"    .09302326
    30393 "CHEWA"    .023255814
    30393 "TONGA"     .23255815
    30393 "LOZI"       .1744186
    30393 "LOZI"       .1744186
    30393 "LOZI"       .1744186
    30393 "LOZI"       .1744186
    30393 "TONGA"     .23255815
    30393 "TONGA"     .23255815
    30393 "BEMBA"      .1627907
    30393 "TONGA"     .23255815
    30393 "TONGA"     .23255815
    30393 "LOZI"       .1744186
    30393 "TONGA"     .23255815
    30393 "TONGA"     .23255815
    30393 "TONGA"     .23255815
    30393 "TONGA"     .23255815
    30393 "TONGA"     .23255815
    30393 "ILA"      .023255814
    30393 "TONGA"     .23255815
    30393 "NYANJA"   .011627907
    30393 "LOZI"       .1744186
    30393 "TONGA"     .23255815
    30396 "TONGA"      .3888889
    30396 "TONGA"      .3888889
    30396 "TONGA"      .3888889
    30396 "TONGA"      .3888889
    30396 "TONGA"      .3888889
    30396 "TONGA"      .3888889
    30396 "TONGA"      .3888889
    30396 "TONGA"      .3888889
    30396 "TONGA"      .3888889
    30396 "TONGA"      .3888889
    30396 "TONGA"      .3888889
    30396 "TONGA"      .3888889
    30396 "TONGA"      .3888889
    30396 "TONGA"      .3888889
    end




  • #2
    search egen.

    look at "cut"

    Comment


    • #3
      Olivia:
      as George wrote, -egen- can help you out here:
      Code:
      egen counter=group( ethnicity)
      bysort delid: egen wanted=pc( counter )
      Then you have the -label- the -counter- variable with the different -ethnicity-.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment

      Working...
      X