Choosing values free of NA
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Choosing values free of NA
Dear Tom,
I have a vector series consisting of 400+ observation some of which are %na, I would like to choose 61 values among the 400+ free of %na and repeat generation of 61 values free of %na 1,000 times. Is there a way to do this in Rats? Please advise
Many thanks in advance
Rachid
I have a vector series consisting of 400+ observation some of which are %na, I would like to choose 61 values among the 400+ free of %na and repeat generation of 61 values free of %na 1,000 times. Is there a way to do this in Rats? Please advise
Many thanks in advance
Rachid
Re: Choosing values free of NA
Something like:
set source 1 450 = %if(%ranflip(.95),%ran(1.0),%na)
*
sample(smpl=%valid(source)) source / goodsource
boot entries 1 61 1 %nobs
set draw 1 61 = goodsource(entries(t))
You use SAMPLE with get rid of the NA's then use BOOT to sample the valid ones.
set source 1 450 = %if(%ranflip(.95),%ran(1.0),%na)
*
sample(smpl=%valid(source)) source / goodsource
boot entries 1 61 1 %nobs
set draw 1 61 = goodsource(entries(t))
You use SAMPLE with get rid of the NA's then use BOOT to sample the valid ones.
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Choosing values free of NA
Many thanks for your inputs. Does Rats 6.2 version contain the function %ranflip()? is %ranpermute(n) an equivalent function?
Thanks
Rachid
Thanks
Rachid
Re: Choosing values free of NA
No, but that's only to generate sample data. You have your own version of "source".rbelhach95 wrote:Many thanks for your inputs. Does Rats 6.2 version contain the function %ranflip()? is %ranpermute(n) an equivalent function?
Thanks
Rachid
%RANFLIP(p) was added with 8.2. It can be done in earlier versions of RATS with (%uniform(0,1)<p).
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Choosing values free of NA
Many thanks Tom
Rachid
Rachid
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Choosing values free of NA
Dear Tom,
Hope all is well. When I print / draw (code is below) I still get few NA among the 61 observations. Please advise
Many Thanks
Rachid
Hope all is well. When I print / draw (code is below) I still get few NA among the 61 observations. Please advise
Many Thanks
Rachid
Code: Select all
do rep = 1,100
set v = %ran(1.0)
...........
............
set R1(rep) = -psinustr0+psinustr1+estr
sample(smpl=%valid(R1(rep))) R1(rep) / goodsource
boot entries 1 61 1 %nobs
set draw 1 61 = goodsource(entries(t))
end do repRe: Choosing values free of NA
put the 1 at the end of this:
sample(smpl=%valid(R1(rep))) R1(rep) / goodsource 1
Otherwise it might shift the data if R1 has missing values at the start.
sample(smpl=%valid(R1(rep))) R1(rep) / goodsource 1
Otherwise it might shift the data if R1 has missing values at the start.
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Choosing values free of NA
Many thanks Tom for the feedback. I have added 1 after goodsource, but I still get NA in draw. Please advise
Thanks
Rachid
Thanks
Rachid
Code: Select all
ENTRY DRAW
1971:03 0.009987129896
1971:04 0.089264501125
1971:05 -0.066277303726
1971:06 0.034482091127
1971:07 NA
1971:08 0.028019166636
1971:09 NA
1971:10 0.002410742052
1971:11 0.009987129896
1971:12 0.011234568583
1972:01 0.196553099441
1972:02 -0.090971325404
1972:03 NA
1972:04 0.096994397199
1972:05 -0.122666725915
1972:06 -0.004744943820
1972:07 NA
1972:08 0.130441242877
1972:09 NA
1972:10 0.058699953278
1972:11 -0.006844476663
1972:12 0.051097005690
1973:01 0.000913463102
1973:02 NA
1973:03 -0.019589709634
1973:04 0.028831200672
1973:05 NA
1973:06 0.013102866851
1973:07 0.040987096204
1973:08 0.017601301523
1973:09 NA
1973:10 -0.067871752675
1973:11 0.038154769307
1973:12 0.075112074084
1974:01 0.011234568583
1974:02 0.055478393405
1974:03 0.051117280703
1974:04 0.028831200672
1974:05 -0.015470479007
1974:06 0.009606881975
1974:07 0.050848591308
1974:08 -0.088281064833
1974:09 0.019939464135
1974:10 0.031441730602
1974:11 0.069240473027
1974:12 -0.006844476663
1975:01 0.009943722821
1975:02 0.089264501125
1975:03 0.089370631102
1975:04 0.095017754493
1975:05 -0.009238696336
1975:06 -0.005077467003
1975:07 -0.035146571003
1975:08 0.052829071588
1975:09 0.098658641980
1975:10 0.020255125054
1975:11 0.002410742052
1975:12 -0.013834376261
1976:01 0.073641693926
1976:02 -0.004495060021
Re: Choosing values free of NA
You'll have to post your whole program. It works fine as far as I can tell.
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Choosing values free of NA
Dear Tom,
Hope all is well. Kindly find the attached code, I still have the same problem of getting NAs. I also run to a problem when N=number of replication is over 10,000, the code runs for a while then it shows "RATS NOT RESPONDING" but for 5000 or less it works fine. Please advise
Thanks
Rachid
Hope all is well. Kindly find the attached code, I still have the same problem of getting NAs. I also run to a problem when N=number of replication is over 10,000, the code runs for a while then it shows "RATS NOT RESPONDING" but for 5000 or less it works fine. Please advise
Thanks
Rachid
- Attachments
-
- Code_Test.PRG
- (3.47 KiB) Downloaded 999 times
Re: Choosing values free of NA
Why is the SAMPLE outside the DO REP loop?
end do rep
sample(smpl=%valid(R1(rep))) R1(rep) / goodsource 1
boot entries 1 61 1 %nobs
set draw 1 61 = goodsource(entries(t))
print / R1
end do rep
sample(smpl=%valid(R1(rep))) R1(rep) / goodsource 1
boot entries 1 61 1 %nobs
set draw 1 61 = goodsource(entries(t))
print / R1
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Choosing values free of NA
Thanks Tom for the feedback. Should the end of the code look like this:
Many thanks
Rachid
Code: Select all
set psinustr1 = log(m_1)
set R1(rep) = -psinustr0+psinustr1+estr
sample(smpl=%valid(R1(rep))) R1(rep) / goodsource 1
boot entries 1 61 1 %nobs
set draw 1 61 = goodsource(entries(t))
end do rep
print / draw
Rachid
Re: Choosing values free of NA
While that's better than using REP outside the REP loop, I don't see what you're trying to accomplish. This will generate a new DRAW series each time through the REP loop and then overwrite it the next time through. It would help you to learn how to use "pseudo-code" to organize what you're doing first without being as concerned about the precise programming code:
Also, please get in the habit of indenting your loops.
Kernighan is one of the co-authors of the C programming language (among many other things), so he knows a thing or two about how to program....written in a pseudo-code that resembles a computer language but
avoids excessive detail by lapsing from time to time into ordinary
English. This lets us specify quite a bit of the program before we
have worked out all aspects of it. On larger programs, it is
valuable to begin with pseudo-code and refine it in stages until
it is all executable. This way you can revise and improve the
design at a high level without writing any executable code, yet
remain close to a form which can be made executable.
(Software Tools, Kernighan, Plauger)
Also, please get in the habit of indenting your loops.
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Choosing values free of NA
Many thanks for your advice
Rachid
Rachid