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]

From |
Maarten Buis <[email protected]> |

To |
[email protected] |

Subject |
Re: st: Transforming data - horizontal to vertical |

Date |
Wed, 11 May 2011 14:39:15 +0200 |

On Wed, May 11, 2011 at 1:48 PM, lreine ycenna wrote: > I tried the command ds gdp year, not local countries `r(gdp)', but > stata tells me option local is not allowed. Looks like you're email program is not displaying statalist messages correctly -ds gdp year, not- and -local countries `r(gdp)'- are two different commands. Look at the statalist archives (for example <http://www.hsph.harvard.edu/cgi-bin/lwgate/STATALIST/archives>) for correctly formatted posts. > am i supposed to create a variable called ' countries'? No, `countries' (in general anything surrounded by a " ` " and a " ' ") is a local macro. In this case, you can think of this as a place where you can store lists of variable names. In general, it is just a place where you can store any string. See: -help macro-. Given that this is a local macro, you will need to run the definition of the local and any subsequent command that uses it in one go. Below is one more example using the data you sent. It now assumes that you have only one variable. It takes care of the commas using -destring-. If you have multiple variables you just combine the tricks that have already appeared in this thread. *--------------------- begin example ------------------------ clear all input year str12 Afghanistan str12 Albania str12 Algeria 1977 "275,820,910" ".." "1,683,573,383" 1978 "390,555,036" ".." "1,980,500,369" 1979 "441,210,990" ".." "2,658,756,710" 1980 "371,168,398" ".." "3,772,614,849" 1981 "274,293,425" ".." "3,695,345,372" end ds year, not local varl `r(varlist)' destring `varl', replace ignore(",") force list foreach var of local varl { rename `var' gdp`var' } reshape long gdp, i(year) j(country) string list *--------------------- end example ---------------------------- (For more on examples I sent to the Statalist see: http://www.maartenbuis.nl/example_faq ) Hope this helps, Maarten -------------------------- Maarten L. Buis Institut fuer Soziologie Universitaet Tuebingen Wilhelmstrasse 36 72074 Tuebingen Germany http://www.maartenbuis.nl -------------------------- * * 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: Transforming data - horizontal to vertical***From:*lreine ycenna <[email protected]>

**Re: st: Transforming data - horizontal to vertical***From:*Maarten Buis <[email protected]>

**Re: st: Transforming data - horizontal to vertical***From:*lreine ycenna <[email protected]>

**Re: st: Transforming data - horizontal to vertical***From:*Maarten Buis <[email protected]>

**Re: st: Transforming data - horizontal to vertical***From:*Nick Cox <[email protected]>

**Re: st: Transforming data - horizontal to vertical***From:*lreine ycenna <[email protected]>

- Prev by Date:
**st: graph rarea optical illusion or coding error?** - Next by Date:
**Re: st: Transforming data - horizontal to vertical** - Previous by thread:
**Re: st: Transforming data - horizontal to vertical** - Next by thread:
**Re: st: Transforming data - horizontal to vertical** - Index(es):