Bookmark and Share

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: Re: Questions for random data generation and value label


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Re: Questions for random data generation and value label
Date   Sat, 9 Mar 2013 08:14:35 +0000

See also -ds- and -findname- (SJ) for canned solutions.

Nick

On 9 Mar 2013, at 07:19, "Joseph Coveney" <[email protected]> wrote:

Yu Xue wrote:

I have two questions:

Question 1:
I am trying to build up synthetic/fake dataset, using random generated
variables. Of each variable I know:
1) mean
2) standard deviation
3) range of values (min and max values.)
How can I ask STATA to randomly generate a variable with all those
specified parameters?

Question 2:
How to know if a variable has a value label attached? I know I can
take a look at the result of "describe" or use "label list" to list
all value labels. But what I want is a command that can return a value
for each variable to show if it has value label attached or not.

---
---
---
---
--------------------------------------------------------------------

I can't help you with your first question; I'm guessing that, unless the distribution is naturally bounded, you're going to have some trouble juggling
more than two of the three matching requirements.

For your second question, you can use an extended macro function in order to programmatically detect whether a variable has a value label. Type - help extended_fcn- to find out more. There might be better ways that I don't know about or that don't occur to me at the moment, and others can chime in to help
us both there.

Joseph Coveney

. sysuse auto, clear
(1978 Automobile Data)

. foreach var of varlist make gear_ratio foreign {
 2. local value_label : value label `var'
3. if "`value_label'" != "" display in smcl as text "`var' has value labels"
 4. else display in smcl as text "`var' doesn't have any value labels"
 5. }
make doesn't have any value labels
gear_ratio doesn't have any value labels
foreign has value labels
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index