Announcement

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

  • How to convert a single column into multiple rows

    Hi there,
    A newbie here. I have been trying to convert my data for hours but could not manage to do so. Any help is greatly appreciated.
    I have data for 50 US states and this is how my data looks:
    year state unemp
    2020 Alabama 5.5
    2021 Alabama 4.5
    2022 Alabama 4.0
    2020 Alaska 6.2
    2021 Alaska 6.0
    2022 Alaska 6.5
    2020 Arizona 4.3
    2021 Arizona 3.4
    2022 Arizona 3.1
    ... ..... ...
    How can I convert it to look like this:
    Year Alabama (unemp) Alaska (unemp) Arizona (unemp)
    2020 5.5 6.2 4.3
    2021 4.5 6.0 3.4
    2022 4.0 6.5 3.1

  • #2
    I advise that you do not do this. Your data is in long layout which is ideal for analysis. If you are facing a specific problem with manipulating the data in long layout, describe the problem directly.

    Comment


    • #3
      Thanks for the heads-up.
      I am trying to find sigma convergence which is basically calculating the standard deviation among the states for each year.

      Comment


      • #4
        I am trying to find sigma convergence which is basically calculating the standard deviation among the states for each year.
        I'm not familiar with sigma convergence, but calculating the standard deviation among the states for each year is very straightforward with the long data layout you have:
        Code:
        by year, sort: egen wanted = sd(unemp)

        Comment


        • #5
          Thanks much, Clyde. Clearly, I was on the wrong path. I should keep working on how to handle the data. Also, these answers made me feel why I should keep using the Stata as there is always someone out there who can help.

          Comment

          Working...
          X