Announcement

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

  • Reshaping to long format

    Hello,

    I am currently trying to reshape a dataset to the long format.

    I have monthly return data over several years for 100 stocks. The months represented in the rows, the company id´s (e.g. US9129091081) in the columns (the returns are below the id´s therefore). Additionally I have monthly market returns as the last column, similar to the companies. I want to create a panel data set (long format), where every company is listed in the rows with the corresponding date and the market return on that month. Hence I want to assign the market returns of every month to every company as well.

    I first created stub names for every single company. I just added a ret prefix to every id. Then I entered the following code:

    Code:
    reshape long ret, i(date) j(id) string
    Then I entered:
    Code:
    sort id date
    Could you please verify, if the code is indeed correct? I was not sure, because I completely excluded the market variable in the reshape command. I would appreciate a short feedback. Thank you in advance

  • #2
    A verbal description of a data structure/layout is almost never clear enough to support good advice from another person. That's one of various reasons why the FAQ new StataList members are advised to read describes the use of the -dataex- command to provide example data. I'd encourage you to reread about -dataex- in that FAQ (tab at the top of the page) and provide such an example.

    Comment

    Working...
    X