Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: AW: AW: RE: AW: RE: RE: reshape command ---listing all the variables changing over time? |

Date |
Fri, 14 May 2010 12:53:28 +0100 |

I am sure you are right. I suppose that almost always I -reshape long-, which is why the point has not registered with me. Nick n.j.cox@durham.ac.uk Martin Weiss Also, the dialog box at -db reshape- offers a drop-down for the variables of the current dataset, whether the radio button at the top is set to "long format from wide" or "wide format from long". So there is every reason to think that users will fill in a -varlist-, not a "stub". Martin Weiss " I can't see where that's promised or implied." Amanda`s post did keep me busy last night due to this slight inconsistency in the help file. If you let Stata ************* reshape wide x, i(id) j(j) ************* in my example, it complains: x ambiguous abbreviation r(111); So that points to the expansion of a -varlist-, as in *** clear foreach var of newlist x1-x5{ gen `var'=2 } unab mylocal: x *** All of which the help file does not make clear. Still, the variable names thus passed to Stata are actually used as "stubs" for the wide form dataset: . reshape wide x1-x5, i(id) j(j) (note: j = 1 2 3) Data long -> wide ---------------------------------------------------------------------------- - Number of obs. 300 -> 100 Number of variables 12 -> 21 j variable (3 values) j -> (dropped) xij variables: x1 -> x11 x12 x13 x2 -> x21 x22 x23 x3 -> x31 x32 x33 x4 -> x41 x42 x43 x5 -> x51 x52 x53 ---------------------------------------------------------------------------- - HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Nick Cox Gesendet: Freitag, 14. Mai 2010 13:15 An: statalist@hsphsun2.harvard.edu Betreff: st: RE: AW: RE: RE: reshape command ---listing all the variables changing over time? Good point. I was replying directly to Amanda. But in your example and hers, I expected the stubs to be -x-. Bu in fact they are not. It's interesting that -reshape- in parsing a list of stubs will expand a varlist. I can't see where that's promised or implied. I certainly hadn't appreciated it before. Nick n.j.cox@durham.ac.uk Martin Weiss " In addition, your -reshape- example is puzzling." Actually, this was the _one_ aspect that I did not find strange about this post. Which aspect of thie following example do you find puzzling? ************* clear* set obs 100 gen byte id=_n expand 3 bys id: gen byte j=_n foreach var of newlist x1-x5{ //time varying vars gen `var'=rnormal() } foreach var of newlist y1-y5{ //constant vars gen `var'=5 } reshape wide x1-x5, i(id) j(j) ************* HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Nick Cox Gesendet: Freitag, 14. Mai 2010 12:57 An: statalist@hsphsun2.harvard.edu Betreff: st: RE: RE: reshape command ---listing all the variables changing over time? In addition, your -reshape- example is puzzling. -reshape- expects stubs, not variable names. Nick n.j.cox@durham.ac.uk Nick Cox In addition to other replies findname, all(@ == @[1]) finds all variables which are constant; adding its -not- option finds the complement. You can specify a varlist too to separate constant and changing variables. The syntax catches numeric and string variables alike. -findname- is a user-written program from SSC. Amanda Fu I was wondering if anyone could help me with a problem I met when using --reshape--command. When I tried to reshape a data set from long version to wide version, I find I need to list all the variables that are not constant in the --reshape--command. Suppose the data set has 1500 variables changing over time and 100 constant variables. ------------------------------------------------------------ . reshape wide x1-x1500, i(id) j(wave) ------------------------------------------------------------ If I miss any of the variables changing over time, the reshape command will give error message such as "variable XXXX not constant " and will stop working. But it is so frustrating to separate the constant variables and not-constant variables and list all of the latter ones in the reshape command. What I used to do is just to drop all the unnecessary variables from the data set before reshape to reduce the work load here. May I know if there is any more efficient way to deal with this problem? * * 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/

**References**:**st:reshape command ---listing all the variables changing over time?***From:*Amanda Fu <mandy.fu1@gmail.com>

**st: RE: reshape command ---listing all the variables changing over time?***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**st: RE: RE: reshape command ---listing all the variables changing over time?***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**st: AW: RE: RE: reshape command ---listing all the variables changing over time?***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**st: RE: AW: RE: RE: reshape command ---listing all the variables changing over time?***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**st: AW: RE: AW: RE: RE: reshape command ---listing all the variables changing over time?***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**st: AW: AW: RE: AW: RE: RE: reshape command ---listing all the variables changing over time?***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**Antwort: Re: RE: Antwort: st: 'mills' output is missing for heckman regression** - Next by Date:
**Re: st: Comparing Variable Name Labels Between Datasets** - Previous by thread:
**st: AW: AW: RE: AW: RE: RE: reshape command ---listing all the variables changing over time?** - Next by thread:
**st: r(198) frustration--need help** - Index(es):