Announcement

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

  • Rearranging columns and rows to make it country-level database

    I want to create two columns:
    Column A with all the countries listed in the photo below
    Column B with one of 3 options (Advanced Economies, Emerging Market Economies, Low-Income Developing Countries) to match whichever category it is placed under in the photo below.

    So ideally, we'd end up with something that looks like:
    Country Type
    Australia Advanced Economies
    Austria Advanced Economies
    Albania Emerging Market Economies
    Afghanistan Low-Income Developing Countries

    I can do this easily on excel by moving cells around, etc.

    But how do I do this with purely Stata? I realize it's not a wide-to-long format reshaping matter.

    Thank you in advance,


    Click image for larger version

Name:	Screen Shot 2022-11-23 at 3.38.46 PM.png
Views:	1
Size:	92.5 KB
ID:	1690721





  • #2
    Your question is in some sense premature, because the first step to working with your data Stata is to use the import excel command to create a Stata dataset of your Excel data, which you have yet to do.

    In general, you should do that first, before you post, and following the advice of the Statalist FAQ linked to from the top of every page, present a sample of your data using the dataex command. That increases the likelihood that the advice you are given will have been tested on an example of your data and will work for you.

    I realize it's not a wide-to-long format reshaping matter.
    Actually, that's exactly what it is.

    If you rename the variables created from your Excel columns A, B, and C to have the names countryA countryB countryC then the following untested code might start you in a useful direction.
    Code:
    generate seq = _n
    reshape long country, i(seq) j(type) string
    drop seq
    You should have a dataset with two variables now: country will have country names, and type will be A, B, or C, which you can easily replace with "Advanced Economies" for A, and similarly for B and C.

    Comment


    • #3
      William Lisowski
      Thank you sir for your advice and instructions - I am new to this forum.

      Your advice worked!

      Thank you

      Comment

      Working...
      X