Announcement

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

  • Lsemantica command

    Hello,
    I'm trying to calculate cosine similarity using the "lsemantica" command, as I've seen referenced in a few settings including the paper- (https://carloschwarz.eu/wp-content/u.../lsa_stata.pdf) to compare text similarity between two variables (nursing terms and physician terms) in a dataset.

    I'm starting using a very basic test data set with 2 variables and 11 observations that I created simply to ensure a proof of concept. After importing the data set, I am trying to run "lsemantica" and STATA displays a "command lsemantica is unrecognized." I am running Stata 19, BE, and my application is up to date. Here's a log file. I'm probably making some very silly elementary mistake- but welcome insight from the community.




    . view "C:\Users\dfrac\AppData\Local\Temp\19997697-81c2-4b2b-b2b2-f2a51b85a98b_lsemantica(2).zip.lsemantica(2).zip\l semantica.sthlp"

    . log using "C:\Users\dfrac\Documents\IRB - data work\Data test attempt 12-8-2025 v2.smcl"
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    name: <unnamed>
    log: C:\Users\dfrac\Documents\IRB - data work\Data test attempt 12-8-2025 v2.smcl
    log type: smcl
    opened on: 8 Dec 2025, 22:46:27

    . import excel "C:\Users\dfrac\Documents\IRB - data work\Data test.xlsx", sheet("Sheet1") firstrow
    (2 vars, 11 obs)

    . lsemantica nandaexample , components(4) tfidf min_char(3) min_freq(5) max_freq(0.5) name_new_var("component_")
    command lsemantica is unrecognized
    r(199);

    . Thank you so much!

  • #2
    Stata commands divide into (1) those bundled with Stata as distributed by StataCorp or its distributors, which are very often called official, and (2) those written by users and now often called community-contributed, although the older term user-written may still be more common.

    Some small exceptions aside (1) is what you or your workplace paid for (2) are usually freely available but must be installed. StataCorp do not distribute community-contributed commands.

    To use any command under (2) you must have the files for that command installed and also visible to Stata's executable.

    lsemantica is community-contributed.

    Code:
    SJ-19-1 st0552  . . . . . .  Text similarity based on latent semantic analysis
            (help lsemantica, lsemantica_cosine if installed) . . . . . C. Schwarz
            Q1/19   SJ 19(1):129--142
            implements latent semantic analysis

    So either (a) you haven't installed it, or (b) it's on your system but not visible to Stata, so you need to issue an adopath command to alert Stata to where the files are to be found.

    I will run with the first guess (a). If you type in Stata

    Code:
    search lsemantica
    then you should see the text within CODE delimiters above, and can install the command
    lsemantica by clicking on
    Code:
    st0552
    .


    Do this within Stata. Don't try to use a browser to do this.

    EDIT

    Sorry, I didn't read your post carefully enough, but by accident the last sentences apply. It seems that you have downloaded a zipped up package. Perhaps someone sent you the files that way, or you used something other than Stata to download the files. I would back up and install directly as I suggested. The method you used is not a good shortcut.
    Last edited by Nick Cox; 09 Dec 2025, 02:31.

    Comment


    • #3
      Thanks so much! I didn't realize that I had to install the community installed commands, so things are working now!

      Comment

      Working...
      X