Announcement

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

  • Help getting started on ado

    My working software stack is some combination of Stata and Python. I'm in a situation where it would be convenient to write an ado file - spent a day trying to get ChatGPT to help and that was a waste of time. At least it's patient. I am starting from scratch with the code below to just get an idea of how things work.

    program define regress_R2
    args x y
    local n = _N
    local offset = 10
    forval i = `offset'/(`n' - `offset' + 1) {
    display `i'
    }
    end

    When I run this code I get:

    - args x y
    - local n = _N
    - local offset = 10
    - forval i = `offset'/(`n' - `offset' + 1) {
    = forval i = 10/(7954 - 10 + 1) {
    invalid syntax

    Any help would be appreciated. I'm using trace and display to help debug - any better approaches?


  • #2
    The problem with -forval i = `offset'/(`n' - `offset' + 1) {- is that the tokens on either side of the / in a -forval- command must be numbers. Not expressions, simple numbers. Change it to:
    Code:
    forval i = `offset'/`=`n' - `offset' + 1' {
    The `=expression' construct causes Stata to evaluate the expression and then substitute the result into the command. That result will be a single number, and -forval- can digest that.

    By the way, it is the norm in this community that we use our real given and surnames as our user id, to promote collegiality and professionalism. It is not possible for you to edit this in your user profile. But if you click on "Contact Us" in the lower right corner of the page, you can message the system administrator and ask him to do it for you. Thank you for your cooperation.
    Last edited by Clyde Schechter; 09 Jul 2023, 14:17.

    Comment


    • #3
      Thank you Clyde. I've programmed a long time and in many languages, it's these kinds of details that always kill me. Many thanks. (I've also contacted the admin re name change.)

      Comment

      Working...
      X