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]

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


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
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
http://www.stata.com/statalist/archive/2012-09/msg00740.html). 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
http://www.stata.com/statalist/archive/2008-08/msg01258.html

Nick

On Thu, Sep 20, 2012 at 11:24 PM, david parsley <corey1954@gmail.com> 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:
*   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