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 |
Pedro Nakashima <nakashimapedrolist@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Reshape problem |

Date |
Wed, 22 Aug 2012 16:42:38 -0300 |

Thank you very much, James Fiedler It worked perfectly well !! Best, Pedro. 2012/8/22 Fiedler, James (JSC-SK)[UNIVERSITIES SPACE RESEARCH ASSOC-DIV OF SPACE LIFE SCIENCES] <james.fiedler-1@nasa.gov>: > Ok, second attempt. I think this gets what you want, and I think it's general enough to work in a real situation. It's probably not the most elegant solution, though. > > It saves the variable names in individual locals. There might be a better to do this, but I'm guessing this is fine when there are just a few variable names. > > > > input mAug_99 mSep_99 mOct_99 str6 variables > 1 3 5 v1 > 2 4 6 v11 > end > > local N = _N > forv i=1(1)`N' { > local name`i' = variables[`i'] > } > > xpose , varname clear > > local counter = 0 > foreach var of varlist * { > local counter = `counter' + 1 > if ("`name`counter''" != "") { > rename `var' `name`counter'' > } > } > > drop in l > rename _varname month > replace month = substr(month, 2, .) > > > > > James > > ________________________________________ > From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] On Behalf Of Fiedler, James (JSC-SK)[UNIVERSITIES SPACE RESEARCH ASSOC-DIV OF SPACE LIFE SCIENCES] [james.fiedler-1@nasa.gov] > Sent: Wednesday, August 22, 2012 1:52 PM > To: statalist@hsphsun2.harvard.edu > Subject: RE: st: Reshape problem > > Actually, my code doesn't get the variables names the way you want. You'd have to do something differently for that part. > > > ________________________________________ > From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] On Behalf Of Fiedler, James (JSC-SK)[UNIVERSITIES SPACE RESEARCH ASSOC-DIV OF SPACE LIFE SCIENCES] [james.fiedler-1@nasa.gov] > Sent: Wednesday, August 22, 2012 1:47 PM > To: statalist@hsphsun2.harvard.edu > Subject: RE: st: Reshape problem > > Agreeing with the other responses, it does look like you want to transpose the data. Here's some code that (I think) gets the data the way you want it. > > > > input mAug_99 mSep_99 mOct_99 str6 variables > 1 3 5 v1 > 2 4 6 v11 > end > > xpose , varname clear > drop in l > rename _varname month > replace month = substr(month, 2, .) > > > > James > > > ________________________________________ > From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] On Behalf Of Olivia Bacha [oliviabacha@gmail.com] > Sent: Wednesday, August 22, 2012 1:45 PM > To: statalist@hsphsun2.harvard.edu > Subject: Re: st: Reshape problem > > It is not much clear to me what you want to do. If you just want to > transpose your data try > > xpose, clear > > Regards, > Olivia > > 2012/8/22 Dorothy Bridges <dbstata@gmail.com>: >> You could try: >> >> reshape long m, i(variables) j(month) >> reshape wide m, i(month) j(variables, string) >> >> You could also look into xpose and sxpose. >> >> On Wed, Aug 22, 2012 at 11:25 AM, Pedro Nakashima >> <nakashimapedrolist@gmail.com> wrote: >>> Dear statalisters >>> >>> I'm using Stata 12 >>> >>> I'm trying to put a data in the form: >>> >>> input mAug_99 mSep_99 mOct_99 str6 variables >>> 1 3 5 v1 >>> 2 4 6 v11 >>> end >>> >>> into other like: >>> >>> input v1 v11 month >>> 1 2 Aug_99 >>> 3 4 Sep_99 >>> 5 6 Oct_99 >>> end >>> >>> I tryied the command >>> >>> reshape long m, i(variables) j(month) >>> >>> but it didn't create the variables v1 and v11, which I wanted >>> >>> Thanks for any help >>> >>> Best, >>> Pedro. >>> * >>> * 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/ >> * >> * 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/ > * > * 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/ > > * > * 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/ > > * > * 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/ > > * > * 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/ * * 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 problem***From:*Pedro Nakashima <nakashimapedrolist@gmail.com>

**Re: st: Reshape problem***From:*Dorothy Bridges <dbstata@gmail.com>

**Re: st: Reshape problem***From:*Olivia Bacha <oliviabacha@gmail.com>

**RE: st: Reshape problem***From:*"Fiedler, James (JSC-SK)[UNIVERSITIES SPACE RESEARCH ASSOC-DIV OF SPACE LIFE SCIENCES]" <james.fiedler-1@nasa.gov>

**RE: st: Reshape problem***From:*"Fiedler, James (JSC-SK)[UNIVERSITIES SPACE RESEARCH ASSOC-DIV OF SPACE LIFE SCIENCES]" <james.fiedler-1@nasa.gov>

**RE: st: Reshape problem***From:*"Fiedler, James (JSC-SK)[UNIVERSITIES SPACE RESEARCH ASSOC-DIV OF SPACE LIFE SCIENCES]" <james.fiedler-1@nasa.gov>

- Prev by Date:
**Re: st: policy simulation** - Next by Date:
**st: factor variables and qreg?** - Previous by thread:
**RE: st: Reshape problem** - Next by thread:
**st: esttab: unstack halfway?** - Index(es):