Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6740461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:36:31+00:00 2026-05-26T11:36:31+00:00

… and add columns for differences and t-statistics. I learned how to make a

  • 0

… and add columns for differences and t-statistics.

I learned how to make a quantile by quantile table of means and how to add a column/row of differences here (thanks to @lejohn).

Now instead of each row as one quantile of one variable, I would like each row to be a different variable and each cell would be the mean value for each variable for the individuals that fall in each column for the quantile of a given variable.

I can calculate the cell entries easily with tabstat, but I would like the variables in the rows and the quantiles in the columns (tabstat produces the transpose). I would also like the ability to difference columns (as in my first question) and calculate t-statistics for the cell differences.

I feel like the intermediate step is to reshape to long data with three columns: id (here acc_d), variable name, and variable value. But I can’t figure out how to do this and I may be stuck in an R paradigm.

Here is an example of the type table I would like to make

enter image description here

and here is some code with which I have been (unsuccesfully) tinkering

* generate data
clear
set obs 2000
generate acc = rnormal()
generate r1 = rnormal()
generate sar1 = rnormal()
generate arbrisk = rnormal()

* generate quantiles for for a and b
xtile acc_d = acc, nquantiles(10)

* form table (at least my attempts)
* w/ tabstat (but transposed and can't manipulate columns)
tabstat acc r1 sar1 arbrisk, stat(mean) by(acc_d) nototal 

* my attempts to reshape fail, but I would want something like to following to use tabulate
* acc_d   variable    value
* 1       acc         0.01
* 1       r1          1.03
* 1       sar1        -0.03
* 1       arbrisk     0.05
* 2       acc         1.01
* 2       r1          2.03
* 2       sar1        0.03
* 2       arbrisk     1.05

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:36:32+00:00Added an answer on May 26, 2026 at 11:36 am

    Here I would proceed a bit differently. I would first of all gather the information required to compute the difference and the t statistic

    foreach v of varlist acc r1 sar1 arbrisk {
        summarize `v' if acc_d == 1
        local m_`v'_1 = r(mean)
        local var_`v'_1 = r(Var)
        local n_`v'_1 = r(N)
        summarize `v' if acc_d == 10
        local m_`v'_10 = r(mean)
        local var_`v'_10 = r(Var)
        local n_`v'_10 = r(N)
    }
    

    Then I would proceed by collapsing and transposing the data

    collapse (mean) acc r1 sar1 arbrisk, by(acc_d)
    xpose, clear varname 
    drop if _varname == "acc_d"
    order _varname
    forvalues n = 1 / 10 {
        rename v`n' acc_d`n'
    }
    

    In a last step, I would add the difference and the t statistic:

    generate diff_d10_d1 = . 
    generate tstat_d10_d1 = .
    foreach v in acc r1 sar1 arbrisk {
        replace diff = `m_`v'_10' - `m_`v'_1' if _varname == "`v'"
        replace tstat = (`m_`v'_10' - `m_`v'_1') / sqrt((`var_`v'_10'/`n_`v'_10') + (`var_`v'_1'/`n_`v'_1')) if _varname == "`v'"
    }
    

    And finally print the results:

    list, abb(12) noobs
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('…')
I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
English is not my native language. I need a software to spellcheck and correct
what about this one: I want to format the currentTime displayed by a videoPlayer
I have been making a wordpress template. i got stuck at some place... the
(tl;dr: see summary at the bottom.) I am implementing an application that pulls content
I want to sign a message according to the RSA-SHA1 Signature Method in OAuth
I want to run this <!-- This will remove the tag --> <xsl:template name=remove-html>
When I use the list function: el_nino_1974_2000_all <- list() for (k in seq_along(el_nino_start_month)){ el_nino_1974_2000_all[[k]]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.