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: combining variables
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: combining variables
Date
Thu, 2 May 2013 14:41:03 +0100
You could put your key values in a small dataset and then -merge- with
your main dataset.
It's difficult to say whether that would be faster.
But I suspect that it would be much easier to check, because you could
check the table of values more easily as data than as constants
embedded in lots of syntax. So, if this were my problem, I would do it
via a -merge-.
In fact, you presumably have such a table any way, so it should easy
to read it into Stata as data.
Nick
[email protected]
On 2 May 2013 14:32, Thomas Norris <[email protected]> wrote:
> I am entering values for; l, m, s for males and females in my dataset. The values of l, m, s depend not only on sex but also on age at birth, for example, males of 32weeks would have l=0.95, m=1.8 and s=0.18, whereas females of the same age would have l=0.89, m=1.71 and s=0.187.
>
> I started generating the l,m,s scores for males at 32 weeks using 'gen l=0.95 if gest==32 & sex==0' 'gen m=1.80 if gest==32 & sex==0' 'gen s=0.180 if gest==32 & sex==0'
> and then for females at 32 weeks using gen 'l2=0.89 if gest==32 & sex==1' 'gen m2=1.71 if gest==32 & sex==1' 'gen s2=0.187 if gest==32 & sex==0'.
>
> This is quite time consuming as I have to enter l,m,s scores for males and females for each week from 32-42. Is there a quicker way of entering these?
>
> Furthermore, as you can see, if I continue until 42 weeks, I will have variables going from l-l22, m-m22 and s-s22. How can I combine these so I finish with only 1 variable for each?
> I looked at the literature and thought -forvalues- might do this job, but I was unsuccessful.
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/