Announcement

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

  • StataStan issue with stan.ado: "code follows on same line as open brace"

    Hello statalist,

    I am trying to get started with StataStan, but am having problems with the installation. In fact, I am unable to make the Bernoulli example work (it works fine if I launch it from terminal on my Mac). The error message I get is as follows:

    Code:
    program error:  code follows on the same line as open brace
    (error occurred while loading stan.ado)
    r(198);
    I have tried to look at the stan.ado file, but have no idea what is going on (stan.ado file attached). The file is installed in the Stata/ado/personal folder in Library (I am working on a Mac).

    The code I use is as follows (though I get the same error if I use the other options in the example)

    Code:
    if lower("$S_OS")=="windows" {
        !copy examples\bernoulli\bernoulli.stan bernoulli.stan
    }
    else {
        !cp ./examples/bernoulli/bernoulli.stan bernoulli.stan
    }
    
    // make your data
    clear
    set obs 10
    gen y=0
    replace y=1 in 2
    replace y=1 in 10
    count
    global N=r(N)
    
    // call Stan, providing the modelfile option
    stan y, modelfile("bernoulli.stan") cmd("$cmdstandir") globals("N")
    Any hint is much appreciated!

    Ferdinand
    Attached Files

  • #2
    The file stan.ado is in Rich Text Format. Here is the first paragraph:
    Code:
    {\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf830
    {\fonttbl\f0\fnil\fcharset0 Consolas;\f1\fnil\fcharset0 HelveticaNeue;}
    {\colortbl;\red255\green255\blue255;\red27\green31\blue34;\red109\green109\blue109;\red21\green23\blue26;
    \red87\green96\blue106;\red203\green35\blue57;\red6\green33\blue79;\red70\green77\blue86;}
    {\*\expandedcolortbl;;\cssrgb\c14118\c16078\c18039;\cssrgb\c50196\c50196\c50196;\cssrgb\c10588\c12157\c13725\c29804;
    \cssrgb\c41569\c45098\c49020;\cssrgb\c84314\c22745\c28627;\cssrgb\c1176\c18431\c38431;\cssrgb\c34510\c37647\c41176;}
    \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
    \deftab720
    Perhaps someone opened the file in MS Word and saved it again.

    On a separate note, please always identify the source of commands that you are using (see section 12 of the FAQ).

    Comment


    • #3
      Thank you Friedrich, that indeed solved the problem. Unfortunately, now I am getting a new set of errors. First though, I am using stan from SSC (http://econpapers.repec.org/software...de/s458150.htm) on a Mac, OS Sierra 10.12.5. The output is as follows:

      Code:
      /bin/bash: /bin/stanc: No such file or directory
      StataStan version: 1.2.3
      CmdStan version: 
      
      
      cp: /mystanmodel.stan: Permission denied
      
      cp: /mystanmodel.stan: Permission denied
      /Users/nando
      ###############################
      ###  Output from compiling  ###
      ###############################
      
      make: *** No rule to make target `mystanmodel'.  Stop.
      ##############################
      ###  Output from sampling  ###
      ##############################
      
      /bin/bash: ./mystanmodel: No such file or directory
      
      /bin/bash: bin/stansummary: No such file or directory
      #############################################
      ###  Output from optimizing to find mode  ###
      #############################################
      
      /bin/bash: /mystanmodel: No such file or directory
      (1 var, 0 obs)
      lp__ not found
      r(111);
      
      end of do-file
      
      r(111);

      And here is the code I use:

      Code:
      cd "~/Dropbox/myfolder/"
      
      // make the data
      clear
      set obs 10
      gen y=0
      replace y=1 in 2
      replace y=1 in 10
      count
      global N=r(N)
      
      // write the model from Stata into a plain text file
      tempname writemodel
      file open `writemodel' using "mystanmodel.stan", write replace
      #delimit ;
      foreach line in
          "data { "
          "  int<lower=0> N; "
          "  int<lower=0,upper=1> y[N];"
          "} "
          "parameters {"
          "  real<lower=0,upper=1> theta;"
          "} "
          "model {"
          "  theta ~ beta(1,1);"
          "  for (n in 1:N) "
          "    y[n] ~ bernoulli(theta);"
          "}"
      {;
          #delimit cr
          file write `writemodel' "`line'" _n
      }
      file close `writemodel'
      
      // call Stan
      stan y, modelfile("mystanmodel.stan") cmd("$cmdstandir") globals("N") load mode
      No idea what is going wrong here, and I could not find anything on the net. Can anybody help me with this?

      Ferdinand

      Comment


      • #4
        Ferdinand:

        From your display of the errors, it appears that the stan file is not being writtten. Using Windows, I had some issues doing that using the "inline" method, and ended up just doing a stan file myself, and that worked. Can you verify that StataStan has indeed detected the inline text and generated the stan file? Otherwise, just skip the inline method and generate it yourself, to make sure that any error is not due to the "inline parsing syntax" being correct.

        Glenn

        Comment

        Working...
        X