Bookmark and Share

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]

Re: st: Creating new variables from a STATA panel dataset


From   Lucio Vinhas de Souza <lvdesouza@yahoo.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Creating new variables from a STATA panel dataset
Date   Thu, 4 Aug 2011 07:54:10 -0700 (PDT)

Thanks, Anders, still does not seem to be working, see below (SWE is a country identifier for Sweden, i.e, it would be catch series like *_M_UP, *_X_UP, etc. in my dataset, where '*' stands for a three letter-country idnetifier):

. foreach var of varlist swe* {
  2. gen 'new*' = swe*  
  3. }
' invalid name

and if I try to use 'newlist' also, does not work either, see below


. foreach var of varlist swe* {
  2. gen 'new*' = swe*  
  3. }
' invalid name
r(198);





--- On Wed, 3/8/11, Anders Alexandersson <andersalex@gmail.com> wrote:

> From: Anders Alexandersson <andersalex@gmail.com>
> Subject: Re: st: Creating new variables from a STATA panel dataset
> To: statalist@hsphsun2.harvard.edu
> Date: Wednesday, 3 August, 2011, 21:09
> Yes, the "wild card" character * can
> be used in Stata to indicate that
> "zero or more characters go here" but only for existing
> variables .
> The -forvalues- and -foreach- commands can be used together
> with
> -generate- to quickly create new variables. See the
> examples in the
> help files.
> 
> Anders Alexandersson
> andersalex@gmail.com
> 
> Lucio Vinhas de Souza <lvdesouza@yahoo.com>
> wrote:
> > Thanks, Nick. Now, as I have several hundred variables
> (as I indicated in my earlier post, which include common
> country codes), it is not really feasible that I write all
> of them in a command. I would assume there should be some
> sort of "wild card" notation that one could use to replace a
> part of the varname in STATA. If I am correct, which would
> be this?
> 
> Nick Cox <njcoxstata@gmail.com>
> wrote:
> >> * cannot be part of a variable name.
> >>
> >>>Lucio Vinhas de Souza <lvdesouza@yahoo.com>wrote:
> >>> Very basic question, for someone that has not
> used
> >>> STATA for several years now: I have a panel
> dataset
> >>> (adequately tis t and iis id) of several
> hundred variables,
> >>> and I want to:
> >>>
> >>> a)    Generate new variables
> >>> b)    Run a xtbond from those new variables
> >>>
> >>> I have been trying to generate new variables
> which are
> >>> change rates form the existing ones. The names
> of the
> >>> existing variables are all variations from the
> format
> >>> “countrycode_extension”. I have been
> trying to
> >>>
> >>> gen
> >>>
> “*_extension_new”=((“*_extension”-“*_extension_new”[_n-1])/
> >>> “*_extension_new”[_n-1])
> >>>
> >>> and always get the message
> >>>
> >>> *invalid name
> 
> *
> *   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index