Reshape

1月 13, 2018

File used for this tip is here: tarek-example

**** This is from S Kaneko January 13, 2018 to Tarek
set more off

use tarek_example.dta, clear

* to add a common term for each variables you want to chagege as value in the new variable “month”.
foreach var of varlist jan-may {
rename `var’ treat`var’
}

reshape long treat, i(id) j(month) string
list

/*** comments from S Kaneko
“reshape long” command generetas a new variable “month” from the wide form using
an existing variable. This existing variable should have the prefix term in front
of each variable name that you want to respahe.

For example of this case;
varables are;
id treatapr treatfeb treatjan treatmar treatmay

Each vars has the prefix of “treat”. This “treat” becomes a new variable when you change
the shape to long with values in wide shape dataset;
and terms afer the prefix are stored in the new variable “month” you assiged in the
command as value.

*/

* to change it to wide shapge again

reshape wide treat, i(id) j(month) string
list

ecoepi