Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: re: sample by() vs. bysort: sample; and some unexpected ssc install


From   Gabi Huiber <ghuiber@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: re: sample by() vs. bysort: sample; and some unexpected ssc install
Date   Mon, 22 Feb 2010 11:29:23 -0500

Thank you, Kit.

mata: mata mlib index

did the trick. Shutting down and restarting Stata had not. That's OK.

As to sample by() vs. bysort: sample, their results are identical if
before sample by() you sort the observations by `strata'. But gsample
is doing something different. It's still not clear to me what that is.
So I tried some further testing, and ran into new trouble: Stata's
"invalid name" error response seems to be both inexplicable and
inconsistent.

Here is my program:

capture prog drop myTest
program myTest

local sysfile   lifeexp
local strata    region lexp

local sample_ct 1
local seed      1234567

drop _all
sysuse   `sysfile'
tempfile my_gsample
sort     `strata'             // (1)
set seed `seed'
gsample  `sample_ct', strata(`strata') replace
save "`my_gsample'", replace

drop _all
sysuse   `sysfile'
tempfile my_sampleby
sort     `strata'              // (2)
set seed `seed'
sample   `sample_ct', count by(`strata')
save "`my_sampleby'", replace

cf _all using "`my_gsample'"

end

myTest

I get an "invalid name" error in response to the first call to sort
`strata' when hitting the "do" button; I have no idea why, because
that call looks legitimate to me. If on subsequent attempts I just
call myTest by name from the command line, Stata correctly executes
sort `strata' at the first call, but then exits with the same "invalid
name" error on the second call, commented with (2) above. This happens
with both Stata 10 MP and Stata 11 MP.

I'd appreciate any ideas.

Gabi

P.S. Here's the output:

. set tracedepth 1

. set trace on

. do "C:\DOCUME~1\GABIHU~1\LOCALS~1\Temp\STD01000000.tmp"

. capture prog drop myTest

. program myTest
  1.
. local sysfile   lifeexp
  2. local strata    region lexp
  3. local sample_ct 1
  4. local seed      1234567
  5.
. drop _all
  6. sysuse   `sysfile'
  7. tempfile my_gsample
  8. sort     `strata'
  9. set seed `seed'
 10. gsample  `sample_ct', strata(`strata') replace
 11. save "`my_gsample'", replace
 12.
. drop _all
 13. sysuse   `sysfile'
 14. tempfile my_sampleby
 15. sort     `strata'
 16. set seed `seed'
 17. sample   `sample_ct', count by(`strata')
 18. save "`my_sampleby'", replace
 19.
. cf _all using "`my_gsample'"
 20.
. end

.
. myTest
(Life expectancy, 1998)
(0 observations created)
(34 observations deleted)
(note: file C:\DOCUME~1\GABIHU~1\LOCALS~1\Temp\ST_0100004s.tmp not found)
file C:\DOCUME~1\GABIHU~1\LOCALS~1\Temp\ST_0100004s.tmp saved
(Life expectancy, 1998)
  invalid name
r(198);

end of do-file

r(198);

. myTest
----------------------------------------------------------------------------------------------------------------------------
begin myTest ---
- local sysfile lifeexp
- local strata region lexp
- local sample_ct 1
- local seed 1234567
- drop _all
- sysuse `sysfile'
= sysuse lifeexp
(Life expectancy, 1998)
- tempfile my_gsample
- sort `strata'
= sort region lexp
- set seed `seed'
= set seed 1234567
- gsample `sample_ct', strata(`strata') replace
= gsample 1, strata(region lexp) replace
(0 observations created)
(34 observations deleted)
- save "`my_gsample'", replace
= save "C:\DOCUME~1\GABIHU~1\LOCALS~1\Temp\ST_0100004v.tmp", replace
(note: file C:\DOCUME~1\GABIHU~1\LOCALS~1\Temp\ST_0100004v.tmp not found)
file C:\DOCUME~1\GABIHU~1\LOCALS~1\Temp\ST_0100004v.tmp saved
- drop _all
- sysuse `sysfile'
= sysuse lifeexp
(Life expectancy, 1998)
- tempfile my_sampleby
- sort `strata'
= sort region lexp
  invalid name
------------------------------------------------------------------------------------------------------------------------------
end myTest ---
r(198);





On Sat, Feb 20, 2010 at 1:42 AM, Kit Baum <baum@bc.edu> wrote:
> <>
> Gabi said
>
> mm_sample() from -moremata- is required; type ssc install moremata
> r(499);
> end of do-file
> r(499);
>
> Yet I do have moremata. I checked:
>
> . ssc install moremata
> checking moremata consistency and verifying not already installed...
> all files already exist and are up to date.
> .
>
> Has anybody seen this kind of phantom ssc installs before? How did you
> fix yours?
>
>
> After you install a SSC package containing a Mata object library, you must reindex the list of Mata libraries before the library from the newly-installed package becomes available. Do this by:
>
> (1) quit Stata and start it again, which will create the proper index, or
>
> (2) issue command
>
> mata: mata mlib index
>
> which will do it during the current Stata session.
>
> Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
>                              An Introduction to Stata Programming  |   http://www.stata-press.com/books/isp.html
>   An Introduction to Modern Econometrics Using Stata  |   http://www.stata-press.com/books/imeus.html
>
>
> *
> *   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index