Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Any capability


From   "victor michael zammit" <[email protected]>
To   <[email protected]>
Subject   st: Re: Any capability
Date   Fri, 10 Sep 2004 15:54:42 +0200

Dear Statalist,
given a  do-file ,such as the one that follows , is there any capability to
save  the valid  variables before the program gets to  the next  < set obs
`1' > ,and thus be able to find the relevant variables again after the
program is through ?

. capture program drop meansd

. program define meansd
1. quietly {
2. set more off
3. local i = 1
4. while `i'<= 1000   {
5. clear
6. set obs `1'
7. gen a`i' = 50+10*invnorm(uniform())
8. save a`i',replace
9. summ
10. set obs 1000
11.
. gen mean = .
12. gen sd    = .
13. gen i = .
14. replace mean = r(mean) in `i'
15. replace sd = r(sd) in `i'
16. replace i = `i' in `i'
17. keep mean sd i
18. keep in `i'
19. sort i
20. save i`i',replace
21. local i = `i'+1
22. }
23. use i1,clear
24. local i = 1
25. while `i'<= 1000   {
26. merge i using i`i'
27. drop _merge
28. sort i
29. local i = `i'+1
30. }
31. }
32. keep if mean>49.9 & mean<50.1 & sd>9.9& sd<10.1
33. list
34. end

. meansd 100
(995 observations deleted)

+---------------------------+
mean         sd     i
---------------------------
1.  49.92186   10.07411     2
2.  50.06145   9.908244    88
3.  49.94671   10.08397   109
4.   50.0706   9.960301   215
5.  50.01047     9.9222   722
+---------------------------+

. meansd 200
(984 observations deleted)

+---------------------------+
mean         sd     i
---------------------------
1.  49.96996   9.978514    76
2.  49.92636   10.07861   118
3.  49.97271   10.07149   122
4.  50.07562   10.07239   218
5.  49.94316   9.913686   220
---------------------------
6.  50.02873   10.05811   346
7.  50.01596   10.04384   442
8.  50.00026   9.943673   513
9.  49.91186    9.95947   533
10.  50.00311   10.00525   629
---------------------------
11.  50.09705   9.929688   653
12.  49.98079   10.04592   678
13.  49.93727   9.962771   686
14.  49.98563   10.07247   694
15.  50.08827   9.936735   833
---------------------------
16.  49.97584   10.05994   854
+---------------------------+

. meansd 300
(977 observations deleted)

+---------------------------+
mean         sd     i
---------------------------
1.  50.02181   9.933003    66
2.  49.90105   10.02149    94
3.  49.91893   9.919211   124
4.  50.04763   9.961384   138
5.    50.097   10.07813   206
---------------------------
6.  50.05898   9.987234   259
7.  50.03423   9.955764   274
8.  49.90948   10.01387   304
9.  49.94732   9.985778   335
10.  49.90786   10.08386   338
---------------------------
11.   50.0072    9.95091   399
12.  49.93724   10.00748   426
13.  49.95889   10.09958   470
14.   50.0049   9.944254   488
15.  49.92678   10.05883   499
---------------------------
16.  50.00874   10.00746   500
17.  50.00669   9.937348   531
18.  50.07028   9.987976   532
19.  49.96707   10.06919   623
20.  50.06363    10.0947   757
---------------------------
21.  50.06802   10.03914   778
22.  50.07304   9.979012   830
23.  49.99155   9.969816   839
+---------------------------+

. meansd 400
Break--
r(1);

 Thank you before hand,
Victor Michael Zammit

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index