Announcement

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

  • mnsp command to execute R in Stata

    Hello,

    I'd like to estimate propensity scores for multiple treatments and try to use the mnps command in Stata (https://www.rand.org/statistics/twang/downloads.html). I have followed the codes suggested by online tutorial. However, I am facing the following error: Fatal error: you must specify '--save', '--no-save' or '--vanilla'. I would be grateful if you could advise something to address this issue.

    Code:
    .
    
    global ado "/Users/smp462/Desktop/State/twang/ado files"
    adopath + "$ado"
    
    mnps st $demo $race $income $edu $married $dual $living $area $health1 $health2 i.year, ///
       ntrees(3000) intdepth(3) shrinkage(0.01) ///
       stopmethod(es.mean ks.mean) estimand(ATE) ///
       rcmd(/usr/local/bin/r/) ///
       objpath(/Users/smp462/Desktop/Stata/twang/output) ///
       plotname(/Users/smp462/Desktop/Stata/twang/mnps_example_plot.pdf)
    
    Running R script, please wait...
    
    ARGUMENT '/Users/smp462/Desktop/Stata/twang/output/mnps.R' __ignored__
    
    Fatal error: you must specify '--save', '--no-save' or '--vanilla'
    Error: R did not complete successfully.
    file /Users/smp462/Desktop/Stata/twang/output/mnps.Rout not found
    r(601);
    FYI, the following is the codes suggested by online tutorial (https://www.rand.org/statistics/twan...-tutorial.html).
    Code:
    mnps treat illact crimjust subprob subdep white, ///
    ntrees(3000) intdepth(3) shrinkage(0.01) ///
    stopmethod(es.mean ks.mean) estimand(ATE) ///
    rcmd(C:\Program Files\R\R-3.3.1\bin\Rscript.exe) ///
    objpath(C:\Users\username\twang\output) ///
    plotname(C:\users\username\twang\output\mnps_example_plot.pdf)
    save C:\Users\username\twang\output\aod_ate_wgts, replace
    Thank you in advance!

  • #2
    Was this
    Code:
    global ado "/Users/smp462/Desktop/State/twang/ado files"
    supposed to have been
    Code:
    global ado "/Users/smp462/Desktop/Stata/twang/ado files"

    Comment


    • #3
      mnsp command to execute R in Stata

      Hello,

      I also would like to estimate propensity scores for multiple treatments and try to use the mnps command in Stata (https://www.rand.org/statistics/twang/downloads.html). I have followed the codes suggested by online tutorial. However, I am facing the following error:

      Click image for larger version

Name:	QQ图片20200709081212.png
Views:	1
Size:	39.7 KB
ID:	1562529

      My code:
      use C:\Users\WYH\Desktop\07010110\output\6.20.dta,clea r
      adopath+"C:\Program Files (x86)\Stata15\ado\base\adofiles"
      global aa"race sex diagnisticperiod subtype summarystage age marriedstatus ses"
      mnps insurancedstatus $aa, ntrees(3000) intdepth(3) shrinkage(0.01)
      permtestiters(0) stopmethod(es.mean ks.mean) estimand(ATE)
      rcmd(C:\Program Files\R\R-4.0.2\RStudio\bin\rstudio.exe)
      objpath(C:\Users\WYH\Desktop\07010110\output4)
      plotname(mnps_example_plot.pdf)
      save aod_ate_wgts, replace
      Thank you in advance!

      Comment


      • #4
        The triple slash at the end is an instruction for do files which tells Stata that the command continues on the next line. Your mistake is that those 5 lines need to be executed from a do file, all at once. You can open the do file editor to get started.

        Comment


        • #5
          Originally posted by Leonardo Guizzetti View Post
          The triple slash at the end is an instruction for do files which tells Stata that the command continues on the next line. Your mistake is that those 5 lines need to be executed from a do file, all at once. You can open the do file editor to get started.
          Thanks. I open the do file editor to get started as you advice and I am facing the following error:
          Click image for larger version

Name:	2.jpg
Views:	1
Size:	369.7 KB
ID:	1562595
          Click image for larger version

Name:	1.jpg
Views:	1
Size:	302.4 KB
ID:	1562596

          My do code:
          Click image for larger version

Name:	3.jpg
Views:	1
Size:	116.6 KB
ID:	1562597

          Comment


          • #6
            Please the FAQ. You will learn that posting screenshots are not as useful as you may think.

            You have corrected your initial problem with Stata, but have encountered another with R. This is beyond me as I am not familiar with the packages you are using, nor do I run R from within Stata. Reading the R error suggests that you are likely missing packages (like gridExtra) so I would investigate that further.

            Comment

            Working...
            X