Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: reshape and overtime variation
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: reshape and overtime variation
Date
Wed, 13 Nov 2013 19:15:26 +0000
Suppose you have a bundle of variables, that may or may not be
constant over time. Then
gen isconstant = .
gen ismissing = .
foreach v of var <varlist> {
replace ismissing = missing(`v')
bysort ismissing panel_id (`v') : replace isconstant = `v'[1] == `v'[_N]
su isconstant, meanonly
if r(min) == 1 {
local NOTFIX `NOTFIX' `v'
}
}
If variables are constant, then the first and last are always
identical after sorting. But you need to segregate missings. (This
assumes all missings are system missing, not any of .a ... .z.)
Or
foreach v of var <varlist> {
egen panel_sd = sd(`v'), by(panel_id)
su panel_sd, meanonly
if r(min) == 0 {
local NOTFIX `NOTFIX' `v'
}
drop panel_sd
}
If variables are constant, then their SD will be 0.
Nick
[email protected]
On 13 November 2013 18:54, <[email protected]> wrote:
> Der Stata-list-users,
>
> I am working with a balanced panel dataset in long format (that also includes missing values). The dataset has more than 200 variables. Some of these variables vary over time, others do not.
>
> I want to reshape the dataset into a wide format without loosing any information. For this purpose I would like to create a local -NOTFIX- which should only contain all variable names of variables that are (within all observation units) constant over time.
>
> My ultimate aim is then to type: reshape wide `NOTFIX', i(unit_id) j(year)
>
> My question: Can anyone provide a suggestion on how to create NOTFIX?
>
> Many thanks!
> Darjusch Tafreschi
>
>
>
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/