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: How to generate a censored random variable


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: How to generate a censored random variable
Date   Thu, 6 Feb 2014 17:54:52 +0000

You don't need to do that any way.

. set obs 10
obs was 0, now 10

. gen foo = min(max(0, rnormal(0,1)), 2)

. l

     +----------+
     |      foo |
     |----------|
  1. |        0 |
  2. | .9444048 |
  3. | 1.112015 |
  4. |        0 |
  5. |        0 |
     |----------|
  6. |        0 |
  7. |        0 |
  8. |        0 |
  9. | .1321672 |
 10. | .5269327 |
     +----------+

Use -max()- ensure that your values are at least some minimum and
-min()- conversely.

Nick
[email protected]


On 6 February 2014 17:47, Joao Ricardo F. Lima <[email protected]> wrote:
> Nick,
>
> sorry. Can you explain better?
>
> I saw the -help f_rnormal- and the options are -rnormal()-,
> -rnormal(m)- and -rnormal(m,s)- and don't know how can I change the
> range -min()- and -max()- of this function.
>
> Thanks again,
>
> 2014-02-06 Nick Cox <[email protected]>:
>> Why not feed your random values to -min()- and -max()-?
>> Nick
>> [email protected]
>>
>>
>> On 6 February 2014 17:28, Joao Ricardo F. Lima <[email protected]> wrote:
>>> Dear Statalisters,
>>>
>>> How can I create a censored random variable (left=0 and right=2) in
>>> Stata, with mean=0 and sigma=sdpb1?
>>>
>>> I was using - gen erb= rnormal(0,sdpb1)- but the variable isn't
>>> censored. The mean is 0 and std error is sdpb1, but it's out of the
>>> range 0-2.
>>>
>>> In R, the code is:
>>>
>>> erb[n,]=rnorm.trunc(1, t.left = 0, t.right = medb[n], mean = 0, sigma = sdpb1)
>>>
>>> However, I would like to do in Stata.
>>>
>>> Thanks a lot,
>>>
>>>
>>> --
>>> ---------------------------------------------------------
>>> João Ricardo F. de Lima, D.Sc.
>>> Pesquisador A - Economia Aplicada
>>> Embrapa Semiárido
>>> e-mail: [email protected]
>>> fone: +55 (87) 3866-3667
>>> home-page: www.cpatsa.embrapa.br
>>> ----------------------------------------------------------
>>>
>>> *
>>> *   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/
>>
>> *
>> *   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/
>
>
>
> --
> ---------------------------------------------------------
> João Ricardo F. de Lima, D.Sc.
> Pesquisador A - Economia Aplicada
> Embrapa Semiárido
> e-mail: [email protected]
> fone: +55 (87) 3866-3667
> home-page: www.cpatsa.embrapa.br
> ----------------------------------------------------------
>
> *
> *   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/

*
*   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