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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: creating a variable name from observations of a string variable


From   david parsley <corey1954@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: creating a variable name from observations of a string variable
Date   Fri, 21 Sep 2012 12:59:43 -0500

apparently my 1st attempt to post this did not work....I'm trying again.

I have a panel with a string variable identifying the cross-sectional
observations, e.g.,

state    X1    date
AK    70    1990
AL    35    1990
CA    110    1990
KY    56    1990

and I want to create a variable that compares the ith and jth
observations of x1 and
has its variable name taken from transformations of the string
variable 'state', e.g.,

RAKAL = X1(1)/X1(2)    1990
RAKCA = X1(1)/X1(3)    1990
RAKKY = X1(1)/X1(4)    1990
RALCA = X1(2)/X1(3)    1990
RALKY = X1(2)/X1(4)    1990
RCAKY = X1(3)/X1(4)    1990

I want to create all successive comparisons.  So far, I HAVE been able to create
variables R12, R13, R14, R23, R24, R34 using nested forvalues loops.

  by date: gen new`i's`j'=X1[`i']/X1[`j']


But, I'd rather have the variable name more reflective of what they actually are
by using the values of the 'state' variable.

I have searched and searched with no luck on this....Thanks.
*
*   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