Announcement

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

  • #16
    I wouldn't recommend keeping only the first 3-5 letters with drug names because that is likely to result in two different drug names being reduced to the same thing. I would first save a few characters by replacing all double-underscores with single underscores, and then truncate the whole thing at 31 characters. It is far less likely that this will lead to two different things being collapsed to the same. (But I would check if it does!)

    Code:
    replace rxddrug = strtoname(rxddrug)
    replace rxddrug = subinstr(rxddrug, "__", "_", .)
    replace rxddrug = substr(rsddrug, 1, 31)
    by rxddrug (drug_variable), sort: assert drug_variable[1] == drug_variable[_N]
    drop drug_variable
    drop if missing( rxddrug)
    quietly levelsof rxddrug, local(drugs) clean
    If you get an error on the -assert- command, then you have some drug names that agree on their first 32 characters. In that case, some different approach will be needed. Just how to do that would depend on the details of the offending drug names.

    Comment


    • #17
      Originally posted by Clyde Schechter View Post
      I wouldn't recommend keeping only the first 3-5 letters with drug names because that is likely to result in two different drug names being reduced to the same thing. I would first save a few characters by replacing all double-underscores with single underscores, and then truncate the whole thing at 31 characters. It is far less likely that this will lead to two different things being collapsed to the same. (But I would check if it does!)

      Code:
      replace rxddrug = strtoname(rxddrug)
      replace rxddrug = subinstr(rxddrug, "__", "_", .)
      replace rxddrug = substr(rsddrug, 1, 31)
      by rxddrug (drug_variable), sort: assert drug_variable[1] == drug_variable[_N]
      drop drug_variable
      drop if missing( rxddrug)
      quietly levelsof rxddrug, local(drugs) clean
      If you get an error on the -assert- command, then you have some drug names that agree on their first 32 characters. In that case, some different approach will be needed. Just how to do that would depend on the details of the offending drug names.
      Like you mentioned, I did indeed encounter an error with the assert command with some drugs having names longer than 32 characters. In those cases, I manually edited the names to meet the character limits. I am now working to generate an array to work through all the dichotomous variables to generate proportions for each drug and sort the list like you did previously:
      Code:
      foreach v of varlist `drugs' {
      svy, subpop(if !missing(hbp010)): proportion `v'
          matrix M = r(table)
          frame post results ("`v'") (M["b", "1.`v'"])
      }
      frame change results
      gsort -prop
      list, noobs clean

      Comment


      • #18
        I often hear people on Statalist write about putting their results into a matrix. I don't understand why anyone wants to do that. Unless you are going to use matrix algebra, there is no advantage to having the results in a matrix. And, much as I love matrix algebra, I can't see how it would apply to these results. You already have the results in a Stata data set in -frame results-. In fact, they are already sorted. So how will putting them into a matrix help you? What am I missing? There is so much more you can do with the Stata data set than you can in a matrix.

        That said, if you really want a matrix, you can get it directly from the data set in -frame results- with the mkmat command. (See -help mkmat- if you are not familiar with it.)

        Comment


        • #19
          Originally posted by Clyde Schechter View Post
          I often hear people on Statalist write about putting their results into a matrix. I don't understand why anyone wants to do that. Unless you are going to use matrix algebra, there is no advantage to having the results in a matrix. And, much as I love matrix algebra, I can't see how it would apply to these results. You already have the results in a Stata data set in -frame results-. In fact, they are already sorted. So how will putting them into a matrix help you? What am I missing? There is so much more you can do with the Stata data set than you can in a matrix.

          That said, if you really want a matrix, you can get it directly from the data set in -frame results- with the mkmat command. (See -help mkmat- if you are not familiar with it.)
          Dr. Schechter, I misspoke. I am now attempting to passthrough all these new dichotomous variables created to produce svy, subpop(if inAnalysis==1): proportion for each and descending sort the list.

          Comment

          Working...
          X