Announcement

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

  • Help Debugging Invalid Syntax

    Hello fellow Statalisters:
    I am using the ldagibbs user written command, and replicating the procedure outlined in Schwarz (2018) article on how to use the command but I am running into a couple of problems with the code. I keep getting an error r(198) message. Any help in identifying my mistakes would be helpful (I am using Stata 17).

    Using the following code
    Code:
    *list example topics* 
    forvalues i=1/15 { 
         gsort -topic_prob`i´ 
         list title topic_prob`i´ if _n<=15,, str(45) 
         }
    I get the following message:

    Click image for larger version

Name:	Screen Shot 2023-02-28 at 1.02.49 PM.png
Views:	1
Size:	25.7 KB
ID:	1703826



    Using the following code
    Code:
     forvalues i=1/15{
     gsort - topic_prob`i´
     display as error `i´
     list title if _n<5
     replace topic_prob`i´ = float(round(topic_prob`i´,0.0000001))
     gen topic_`i´ = (max_prob==topic_prob`i´)
     }
    I get the following message:
    Click image for larger version

Name:	Screen Shot 2023-02-28 at 12.58.23 PM.png
Views:	1
Size:	31.1 KB
ID:	1703827




    Thanks in advance for your time.

    References
    Schwarz, C. (2018). ldagibbs: A command for topic modeling in Stata using latent Dirichlet allocation. The Stata Journal, 18(1), 101-117.
    Last edited by Diana Hechavarria; 28 Feb 2023, 12:35.

  • #2
    Problem 1: Too many commas in list call.

    Problem 2: Too hard for me to call. But rounding to the nearest part in 10 million and comparing with some other variable is almost doomed to failure because of precision problems. Underneath the user interface Stata works in binary, not decimal.

    Note that

    Code:
    in 1/4
    is shorter and more efficient than

    Code:
    if _n < 5
    although that's not the problem at all.

    Comment


    • #3
      In the first block of code you show, you have two commas after _n <= 15. But only one is allowed there.

      The other problem, which affects both blocks of code is that you are using incorrect quotes for referencing local macro i (the loop iterator). Your left quote ` is correct. But the right quote must be the ordinary, vertical, apostrophe ('). So that will have to be changed throughout.

      Added: Crossed with #2.
      Last edited by Clyde Schechter; 28 Feb 2023, 12:51.

      Comment


      • #4
        Thank you Clyde!

        Comment

        Working...
        X