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]
Re: st: How to use functions within variable names
From
Jakob Fischer <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: How to use functions within variable names
Date
Thu, 18 Aug 2011 07:08:35 +0100 (BST)
Hello, first of all thank you Maarten and Daniel for your input and time.
How rude of me to use that nonsense name, it was solely intended for the email provider. Please excuse this discourtesy.
I tried to keep the example small and simple and focus only on my issue. But here is what I want to do:
I want to reverse sets of variables for groups with different lengths. The example should illustrate it.
*----------- begin example -------------
clear
input a0 a1 a2 a3 c group result0 result1 result2 b0 b1 b2
. 1 2 3 3 1 3 2 1 . . .
. 4 5 . 3 1 . 5 4 . . .
. 6 . . 3 1 . . 6 . . .
. 7 . . 2 2 . 7 . . . .
. 8 . . 2 2 . 8 . . . .
. 9 10 . 2 2 10 9 . . . .
end
compress
list a1 a2 a3 group c
//The result should be in reversed order, always starting with variable result0. Where c is the biggest "length" of a-variables within a group.
list result0 result1 result2 group c
//This is what the final result should look like
//Group 1: c=3 because of observation 1
//Group 2: c=2 because of observation 6
forvalue i=0/2 {
replace b`i'=a`=c-`i''
}
list b0 b1 b2 group c
// Observations 4-6 are not correct
*------------ end example --------------
Unfortunately, as stated by Daniel, Stata takes the c value from the first observation for all observations. Using c[_n] is not working either, but I hope to find a solution to that problem.
-Jakob
*
* 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/