Announcement

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

  • summing observations by id

    Hi all,

    I am sorry if I this may be a trivial question and if it has already been discussed. I searched through the forum but didn't find a solution.

    I have bilateral data on migration and I would like to create a new variable in which the observation of Belgium and Luxembourg are summed, obtaining a "Belgium-Luxembourg" i_country (keeping all other countries and variables.

    The sum (of Total, Male and Female) should be by year, destination country (j_*).

    Could please someone give me some advice??

    Hoping that I have made this clear, thank you in advance!
    i_country i_code i_iso2 i_iso3 j_country j_code j_iso2 j_iso3 year Total Male Female
    Luxembourg 442 LU LUX United Arab Emirates 784 AE ARE 2017
    Belgium 56 BE BEL United Arab Emirates 784 AE ARE 2017
    Belgium 56 BE BEL United Kingdom 826 GB GBR 2017 36822 16373 20449
    Luxembourg 442 LU LUX United Kingdom 826 GB GBR 2017 1714 793 921
    Belgium 56 BE BEL United Republic of Tanzania 834 TZ TZA 2017
    Luxembourg 442 LU LUX United Republic of Tanzania 834 TZ TZA 2017
    Belgium 56 BE BEL United States Virgin Islands 850 VI VIR 2017
    Luxembourg 442 LU LUX United States Virgin Islands 850 VI VIR 2017
    Belgium 56 BE BEL United States of America 840 US USA 2017 36310 17775 18535
    Luxembourg 442 LU LUX United States of America 840 US USA 2017 2626 1290 1336
    Belgium 56 BE BEL Uruguay 858 UY URY 2017
    Luxembourg 442 LU LUX Uruguay 858 UY URY 2017

  • #2
    Stef:
    minor surgery here would imply to export in another .dta the observations concerning Belgium and Luxemburg, -collapse- appropriately and then -append- back to the original file.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Carlo gave excellent advice. Please read the FAQ. There you'll find how to share data\command\output. This is the best approach to entail the precise code you're looking for.
      Best regards,

      Marcos

      Comment


      • #4
        Dear Carlo and Marcos,
        thank you for your reply.
        I think I would go with Carlo's suggestion.

        Thank you again

        Comment

        Working...
        X