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, is already up and running.

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

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

From   Nick Cox <>
Subject   Re: st: creating a variable name from observations of a string variable
Date   Fri, 21 Sep 2012 01:23:42 +0100

Your first post did appear (see If in
doubt, check the archives first.

Your example indicates use of 50 U.S. states. But you appear to want
to -generate- one new variable for each pair of states, which would be
2500 variables, as the ratios a/b and b/a are different in general. If
your example is just notional, and your panels are something else, the
problem is, for all we can see, even larger. Also you evidently have
data for several dates, so what does that imply? What are you going to
do with all those variables?

Note that each variable would just be a constant any way.

One reason why you got no reply first-time round may be that people
couldn't believe what you were asking, or could believe it and did not
want to spell out that it was a bad idea.

One possibility for your comparisons is a matrix. Another is a single
variable for each date in a long data structure.

I suggest that you need to think through what you were asking, or
alternatively explain what I have misunderstood.

Note that in Stata discussions "variable" should mean "variable" in
Stata's sense. For a less gnomic statement, see


On Thu, Sep 20, 2012 at 11:24 PM, david parsley <> wrote:
> 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.
*   For searches and help try:

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