Announcement

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

  • Matsave is Stata

    I need help with figuring out the Matsave command in Stata. Long story short, I am using the following Stata code version 9, which has a Savemat command:

    svy: mean testever, over(invch)
    mat invchns1=e(b)'
    svy: mean test12mo, over(invch)
    mat invchns2=e(b)'
    svy: mean test12m_yes, over(invch)
    mat invchns3=e(b)'

    svy: mean testever, over(hivriskfactor)
    mat hivrisk1=e(b)'
    svy: mean test12mo, over(hivriskfactor)
    mat hivrisk2=e(b)'
    svy: mean test12m_yes, over(hivriskfactor)
    mat hivrisk3=e(b)'

    nptrend testever, by(invch)
    nptrend test12mo, by(invch)
    nptrend test12m_yes, by(invch)

    mat figure2a=invchns1,invchns2,invchns3
    mat figure2b=hivrisk1[2,1],hivrisk2[2,1],hivrisk3[2,1]
    mat figure2=figure2b \ figure2a
    matname figure2 testever test12mo test12m_yes, c(1...) explicit
    matname figure2 riskfactor norisk lowrisk medrisk highrisk, r(1...) explicit
    preserve
    drop _all
    SaveMat figure2 "figure 2"
    restore

    I am trying to create similar matrices using the Matsave command in Stata version 13 (I have already installed the Matsave command) however when doing so, I get the following error codes:

    svy: mean testever, over(invch)
    mat invchns1=e(b)'
    svy: mean test12mo, over(invch)
    mat invchns2=e(b)'
    svy: mean test12m_yes, over(invch)
    mat invchns3=e(b)'

    svy: mean testever, over(hivriskfactor)
    mat hivrisk1=e(b)'
    svy: mean test12mo, over(hivriskfactor)
    mat hivrisk2=e(b)'
    svy: mean test12m_yes, over(hivriskfactor)
    mat hivrisk3=e(b)'

    nptrend testever, by(invch)
    nptrend test12mo, by(invch)
    nptrend test12m_yes, by(invch)

    mat figure2a=invchns1,invchns2,invchns3
    mat figure2b=hivrisk1[2,1],hivrisk2[2,1],hivrisk3[2,1]
    mat figure2=figure2b \ figure2a
    matname figure2 testever test12mo test12m_yes, c(1...) explicit
    matname figure2 riskfactor norisk lowrisk medrisk highrisk, r(1...) explicit
    (ERROR: number of names and rows() or columns() ranges do not match conformability error)
    preserve
    drop _all
    mata Matsave figure2 "figure 2"
    (ERROR: invalid expression)
    restore

    I'd like to know why the rows/columns for my matrix are off and how to properly write the expression in order to output Figure 2.



  • #2
    Can you add some sample data? It's rather hard to debug mata/stata code when you can't actually run anything.

    Comment

    Working...
    X