Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: create a vector from observations


From   "Rajesh Tharyan" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: create a vector from observations
Date   Wed, 8 Feb 2006 10:50:00 -0000

Hi,

Scott and kit

Thanks very much for your help! Just a follow up on the question.. can I
store the mean calculated as a scalar and not a variable? And if I had many
companies would I be able to create a vector of the means??

Thanks very much

Regards
rajesh 



Address      : Room F12, Xfi-Centre for Finance and Investment
University of Exeter, Streatham Court, EX4 4PU
Tel(office)   : 01392262544
Tel(mobile) : 07770565093
Alt.email      : [email protected]

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Scott Merryman
Sent: 08 February 2006 04:00
To: [email protected]
Subject: st: RE: create a vector from observations

-bysort co (month):gen x = sale - (sale[1] + sale[2])/2 if mon>2-


For example:

. input co month sale

        co      month       sale
  1. 1 1 100
  2. 1 2 50
  3. 1 3 200
  4. 1 4 15
  5. 2 1 15
  6. 2 2 55
  7. 2 3 0
  8. 2 4 0
  9. end

. bysort co (month):gen x = sale - (sale[1] + sale[2])/2 if mon>2
(4 missing values generated)

. l, sepby(co) noobs

  +-------------------------+
  | co   month   sale     x |
  |-------------------------|
  |  1       1    100     . |
  |  1       2     50     . |
  |  1       3    200   125 |
  |  1       4     15   -60 |
  |-------------------------|
  |  2       1     15     . |
  |  2       2     55     . |
  |  2       3      0   -35 |
  |  2       4      0   -35 |
  +-------------------------+


Hope this helps,
Scott

> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Rajesh Tharyan
> Sent: Tuesday, February 07, 2006 8:12 PM
> To: [email protected]
> Subject: st: create a vector from observations
> 
> 
> Hi,
> 
> 
> I have a data set of companies and sales for each of the 12 months of the
> year
> 
> The dataset looks like this
> 
> Co�� �month �������sales
> 1��������� 1��������� 100
> 1��������� 2��������� 50
> 1��������� 3��������� 200
> 1��������� 4��������� 15
> 
> 
> I take the mean of the sales in the first two months (only for the first
> two
> months) and generate a variable X
> Which is the difference between this mean sales and the actual sales for
> each month after the second month.
> 
> The final data set should look like this.
> 
> Co�� �month ������sales�� meansales����� X
> 1��������� 1����� 100���������� 75������� .
> 1��������� 2������50������ ���� 75������� .
> 1��������� 3����� 200����� ���� 75�������125
> 1��������� 4������15������� ��� 75��������-60
> 
> 
> 1. Is there a simple way to do this???
> 
> 2. Instead of creating a variable meansales can I store the value as a
> scalar say "m"and proceed with the calculation as gen X=sales-m if
> month>2?
> 
> 3. Also Suppose I had several companies would I be able to create a vector
> of these means and use that vector to generate the values of X for each
> month>2 for each company?
> 
> Any help appreciated...
> Thanks in advance
> 
> Regards
> Rajesh Tharyan
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index