Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: transform the dataset structure


From   "Friedrich Huebler" <[email protected]>
To   [email protected]
Subject   Re: st: transform the dataset structure
Date   Mon, 13 Oct 2008 12:59:39 -0400

Sara,

Use -reshape-. There are probably shorter solutions than mine.

Friedrich


. flist, noobs

  +-------------------------------------------+
  |     year      italy     france    germany |
  |-------------------------------------------|
  |     1980        209        349        256 |
  |     1981        567        235        980 |
  |     1982        129        567        100 |
  +-------------------------------------------+

. ren italy expenditure1
. ren france expenditure2
. ren germany expenditure3
. reshape long expenditure, i(year) j(country)
. lab def country 1 "Italy" 2 "France" 3 "Germany"
. lab val country country
. sort country year
. flist, noobs sep(0)

  +---------------------------------+
  |     year     country   expend~e |
  |---------------------------------|
  |     1980       Italy        209 |
  |     1981       Italy        567 |
  |     1982       Italy        129 |
  |     1980      France        349 |
  |     1981      France        235 |
  |     1982      France        567 |
  |     1980     Germany        256 |
  |     1981     Germany        980 |
  |     1982     Germany        100 |
  +---------------------------------+


On Mon, Oct 13, 2008 at 12:38 PM, sara borelli <[email protected]> wrote:
> Dear Statalist members,
>
> I have the following question.
> I have a dataset of the form:
>
> year  italy   france  germany  ...   ...   ...
> 1980  209      349     256
> 1981  567      235     980
> 1982  129      567     100
> ...
>
> where the numerical values indicate some expenditure levels. I would like to transfor this dataset into a panel creating the new variable "Expenditure", so that that dataset look like:
>
> expenditure  year  country
>    280       1980  italy
>    567       1981  italy
>    129       1982  italy
>    349       1980  france
>    235       1981  france
>    567       1982  france
>    256       1980  germany
>    980       1981  germany
>    100       1982  germany
> .....
>
> any idea on how I can do this?
> thank you in advance for any help
>
> Sara Borelli
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index