Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 'End Duplicates' error in mata programing


    Hello, everyone. I'm Zhang.

    I would like to ask you a question about an 'End Duplicates' error in my mata programming.

    My program is used to compute some matrixs. Considering the computing limit of stata, I need to use mata language. I wrote a do file for mata-stata interaface. I also want to use an ado programmingwhichmakes all kinds of do files run. But the problem is, in my program, the ado programming and the mata programming have the repeated same 'End'. Thus my stata report a error called ‘End Duplicates’.

    So, I would like to ask you two questions.
    First, is it wrong to write like this, and is stata not allowing this?
    Second, if my idea is resaonable, how to code in order to interface mata programming with ado programming?


    My codes are:
    Code:
    /*Define program*/                                                          
    
    program define MYPROGRAM
    version 14.0
    
    /*Define syntax*/                                                          
    
    syntax using/, [name(string)  *
                           [ ... ]   // some other options
                
    use "`using'", clear   // import data
    confirm name `name'
    
         /*Create and Compute Matrix use Mata*/                                                          
    
         mata:
          ...
          create a matrix named MATRIX
          ...
    
         /*End Mata*/
         end
    
    /*End Program*/                  
    end   // you can see that, there are two 'end's make 'end duplicates' and end unrecognize
    Your answer is very important to me.
    Thank you very much for your answer!
    Last edited by Alice Zhang; 29 Dec 2019, 07:27.

  • #2
    Here is a preferred approach: define your Mata code as a function and call it as a single Mata command.
    Code:
    /*Define program*/                                                          
    program define MYPROGRAM
    version 14.0
    /*Define syntax*/                                                          
    syntax using/, [name(string)  *
                           [ ... ]   // some other options
                
    use "`using'", clear   // import data
    confirm name `name'
    
     /*Create and Compute Matrix use Mata*/                                                          
    mata: makematrix()
    
    /*End Program*/                  
    end
    
    /* Define Mata function */
    version 14.0
    mata:
    void makematrix()
    {
          ...
          create a matrix named MATRIX
          ...
    }
    /*End Mata*/
    end
    This advice and more about Mata programming of ado files is found in the output of help mata by clicking on the "M-1 Introduction and Advice" item and then in that output clicking on the "Ado" item.

    Comment

    Working...
    X