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: create local with specific value of a variable

From   daniel klein <>
Subject   Re: st: create local with specific value of a variable
Date   Wed, 20 Feb 2013 18:24:16 +0100

Canned solution

. qui levelsof y if (x == 50) ,l(y50)


Dear Statalist users:

Sometimes I need to save in a local a specific value of a variable and
I cannot do it because creating a local does not support “if” neither
“in” conditions. For instances, let’s suppose that I have two
variables: “x” and “y”. Variable “x” goes from 1 to 100 and “y” is a
random vector. Now, how can I save in a local the value of “y” when
“x” is, for example, 50?  In other words, I would like to do something
like this:

local y50 = y if x == 50

I know that is not possible and it is actually a “heresy” in Stata
language but it might give you an idea of what I need.

Thank you so much for your help and any idea is more that welcome.

*   For searches and help try:

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