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: RE: defining program that is involved with stata and mata interaction
From
Christophe Kolodziejczyk <[email protected]>
To
[email protected]
Subject
Re: st: RE: defining program that is involved with stata and mata interaction
Date
Fri, 8 Jul 2011 16:52:11 +0200
You cannot use mata interactively in a program because end both defines the
end of the program and the end of the use of mata (interactively). You have
to create a mata function that do the mata part and then insert in the
program a call to this function. In other words you have to replace the mata
code with one line of code which calls the mata functon.
for example
program myprog
...your stata code
mata:mymataprog(arg1,arg2,etc.) //<= call of mata function replacing your
code
end
// Definition of your mata function
clear mata
mata:
function mymataprog(arg1,arg2,...)
{
...mata code...
}
end
Hope it helps
Christophe
2011/7/8 Christophe Kolodziejczyk <[email protected]>
>
> You cannot use mata interactively in a program because end both defines the
> end of the program and the end of the use of mata (interactively). You have
> to create a mata function that do the mata part and then insert in the
> program a call to this function. In other words you have to replace the mata
> code with one line of code which calls the mata functon.
>
> for example
>
> program myprog
>
> ...your stata code
>
> mata:mymataprog(arg1,arg2,etc.) //<= call of mata function replacing your
> code
>
> end
>
> // Definition of your mata function
>
> clear mata
> mata:
>
> function mymataprog(arg1,arg2,...)
> {
>
> ...mata code...
>
> }
>
> end
>
> Hope it helps
> Christophe
>
> 2011/7/8 Nick Cox <[email protected]>
>>
>> The problem report here is that "it can not get through", "can not work". That is no detail at all on what happens. Also, the program here is incomplete and we can not see your data, so we can't test it for ourselves. All in all, useful comment is made pretty difficult.
>>
>> What I can see is that you are using different right quote characters. That won't work. Look at the different characters within
>>
>> forvalue k=1/4{
>> replace u`k'=0 if u`k'==. &TR==0
>> }
>> regress e1 `basic' `T' `u', robust
>>
>> My guess is that you are using word processing software to edit your code. Bad idea. Use a text editor and use left quote ` and right quote ' to indicate local macros.
>>
>> Nick
>> [email protected]
>>
>> Zhi Su
>>
>> I write some commands
>>
>> local basic "..."
>> gsort -TR
>> mvprobit (T1=`basic') (T2=`basic') (T3=`basic') (T4=`basic') if TR==1,robust
>> scalar O=e(N)
>> mvppred xbm if TR==1,xb
>>
>> mata
>>
>> N=3000
>>
>> O=st_numscalar("O")
>> .
>> .
>>
>> Y=st_data(k,("T1","T2","T3","T4"))
>>
>> XBM=st_data(k,("xbm1", "xbm2", "xbm3","xbm4"))
>> .
>> .
>> st_store(k,("u1", "u2","u3","u4"),M_c)
>>
>> end
>>
>> forvalue k=1/4{
>> replace u`k'=0 if u`k'==. &TR==0
>> }
>> regress e1 `basic' `T' `u', robust
>>
>>
>> The program process run well when I run them directly.
>>
>> Then I want to bootstrapp the whole process. Therefore, I
>>
>> capture program drop NHreg
>> program define NHreg
>>
>> local basic "..."
>> gsort -TR
>> mvprobit (T1=`basic') (T2=`basic') (T3=`basic') (T4=`basic') if TR==1,robust
>> scalar O=e(N)
>> mvppred xbm if TR==1,xb
>>
>> mata
>>
>> N=3000
>>
>> O=st_numscalar("O")
>> .
>> .
>>
>> Y=st_data(k,("T1","T2","T3","T4"))
>>
>> XBM=st_data(k,("xbm1", "xbm2", "xbm3","xbm4"))
>> .
>> .
>> st_store(k,("u1", "u2","u3","u4"),M_c)
>>
>> end
>>
>> forvalue k=1/4{
>> replace u`k'=0 if u`k'==. &TR==0
>> }
>> regress e1 `basic' `T' `u', robust
>> end
>>
>> I think the defined command "NHreg" will process all the whole progam.
>> Then I run command
>>
>> NHreg
>>
>> But the process can not go through at all.
>>
>> Why the commands can not work through when I put them in "program
>> define NHreg" and use command "NHreg" to run them?
>>
>> *
>> * 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/