# Re: st: RE: ttest, signrank, ranksum with for each?

 From René Geppert To statalist@hsphsun2.harvard.edu Subject Re: st: RE: ttest, signrank, ranksum with for each? Date Mon, 15 Dec 2008 15:56:55 +0100

My variable of interest is the daily percentage bid-ask-spread of stocks, this would be somewhat equal to a scaled stock price. Thus, the requirement of independence of observations is violated. Sorry, but I am not so knowledgable in statistics and not aware of other testing procedures to circumnavigate this restriction.
```
Nick Cox schrieb:
```
The tests you mention are all based on an assumption of independent observations. Even though you are looking at differences, the question still remains whether that is consistent with your ideas about data generating process(es)? Nick n.j.cox@durham.ac.uk
```René Geppert

```
I have data for 2 groups. For the first group I have 6 quarters of observations, for the second group I have 2 quarters. 1. Q 2007 - 2. Q 2008, and 1. Q 2008 - 2. Q 2008 respecively.
```Data are in long format, like this.
Company - Year - Quarter - Variable1 - Group
abc corp - 2007 - 1 - 0.4 - 1
abc corp - 2007 - 2 - 0.1 - 1
abc corp - 2007 - 3 - 0.05 - 1
abc corp - 2007 - 4 - 0.11 - 1
abc corp - 2008 - 1 - 0.70 - 1
abc corp - 2008 - 2 - 0.0 - 1
def corp - 2008 - 1 - 0.1 - 0
def corp - 2008 - 2 - 0.8 - 0
ghi corp...and so on

```
I now want to perform difference in means and difference in medians tests for 'Variable1' for both, changes from quarter to quarter within each group (0 and 1) and differences among the groups within one quarter. Similarly, I want to test for difference in medians using signrank for differences within one group across quarters and within one quarter across groups using ranksum. So: What I basically want to examine is, have there been any significant changes in variable 1 between the quarters and between the groups?
```
```
Because multiple observations exist for 'Quarter', I cannot simply do a command like:
```. ttest Variable1, by(Group) cuz this captures all the quarters at once
I tried nested if-criteria which doesn't work.
```
So I presume this might be possible using a for each command, anyone got an idea?
```

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```
```
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```