<>
You want to make that last line
*************
//replace the last 10 of var5cat to missing for each of its levels
bys var5cat: replace var4=. if _n>_N-10
*************
otherwise you would kill 22 and not 20 observations...
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Martin Weiss
Gesendet: Dienstag, 21. April 2009 10:46
An: [email protected]
Betreff: AW: st: Re: Re: dataset generation
<>
Here is the code, to be inserted before (or even after) the last -list-
command
*************
//drop the last 10 of var5cat for each of its levels
bys var5cat: keep if _n<=_N-10
*************
Careful though! In Stata, you cannot "delete" a "cell", as you can in
spreadsheets. When you -drop-/-keep-, you delete entire rows, i.e.
observations. You could of course set var4 to missing, which may or may not
be closer to your notion of "deletion".
*************
//replace the last 10 of var5cat to missing for each of its levels
bys var5cat: replace var4=. if _n>=_N-10
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Nikolaos Pandis
Gesendet: Dienstag, 21. April 2009 10:18
An: [email protected]
Betreff: Re: st: Re: Re: dataset generation
Dear Martin,
from the last do-file that worked perfectly, how could I delete the last 10
observations from var4 at var5cat==0 and the last 10 observations from var4
at var5cat==1
--- On Mon, 4/20/09, Nikolaos Pandis <[email protected]> wrote:
From: Nikolaos Pandis <[email protected]>
Subject: Re: st: Re: Re: dataset generation
To: [email protected]
Date: Monday, April 20, 2009, 9:31 AM
Dear Martin,
That was great!
Thank you very much.
Nick
--- On Sun, 4/19/09, Martin Weiss <[email protected]> wrote:
From: Martin Weiss <[email protected]>
Subject: st: Re: Re: dataset generation
To: [email protected]
Date: Sunday, April 19, 2009, 7:52 PM
<>
Sorry, you said you wanted separate lb/ub for your newvars:
****
clear*
set obs 100
gen id=_n
//lower bound for var1
local a1 40
//upper bound for var1
local b1 100
//lower bound for var2
local a2 56
//upper bound for var2
local b2 76
//lower bound for var3
local a3 74
//upper bound for var3
local b3 88
//lower bound for var4
local a4 45
//upper bound for var4
local b4 67
forv i=1/4{
gen var`i'=`a`i''+int((`b`i''-`a`i''+1)*runiform())
}
gen var5cat=0
replace var5cat=1 in 51/100
list, noobs h(30)
****
HTH
Martin
_______________________
----- Original Message -----
From: "Martin Weiss" <[email protected]>
To: <[email protected]>
Sent: Sunday, April 19, 2009 6:47 PM
Subject: st: Re: dataset generation
><>
>
> ***
> clear*
> set obs 100
>
> gen id=_n
>
> //lower bound
> local a 40
> //upper bound
> local b 100
>
>
> forv i=1/4{
> gen var`i'=`a'+int((`b'-`a'+1)*runiform())
> }
>
> gen var5cat=0
> replace var5cat=1 in 51/100
>
> list, noobs h(30)
> ***
>
>
> HTH
> Martin
> _______________________
> ----- Original Message -----
> From: "Nikolaos Pandis" <[email protected]>
> To: <[email protected]>
> Cc: <[email protected]>
> Sent: Sunday, April 19, 2009 6:28 PM
> Subject: st: dataset generation
>
>
>> Hi to all,
>>
>> I would like to generate 4 variables that contain a set of integers in a
>> range from 40-100.
>> I would like to select the range per variable.
>> The total number of observations per variable would be 100.
>> Finally, I would like to create a categorical variable with 0 or 1.
>> The first 4 continuous variables, contain 50 values of category 0 and 50
>> of category 1:
>>
>> id var1 var2 var3 var4 var5cat
>>
>> 1 45 43 44 46 0
>> 2 43 42 48 49 0
>> .............................
>> 50 56 48 54 53 0
>>
>> 51 45 43 44 46 0
>> 52 43 42 48 49 0
>> .............................
>> 100 50 48 54 53 0
>>
>> Thank you very much.
>>
>> nick
>>
>>
>>
>> *
>> * 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/
>>
>
> *
> * 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/
>
*
* 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/
*
* 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/
*
* 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/
*
* 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/
*
* 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/