Announcement

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

  • Sum of row

    hi guys,

    how can i sum a row of data (stock price) on stata? I tried to looked up with help functions and some youtube video but couldn't find any helpful resources.

    and also wondering if there is a way to give an equal weighting for each data (to create an equal weighted portfolio)

    Cheers,
    Chris

  • #2
    Dear Chris,

    use egen x=rowtotal(x1 x2 x3) for the summation in the row (must provide a variables list) and collapse (sum) x to compute a total of the column.

    Help references:Best, Sergiy Radyakin

    Comment


    • #3
      Thanks for replying Sergiy.

      I still not quite get how to write the syntax. I have uploaded my data file here, if you don't mind to take a look. I want to calculate the daily return for each stock. So I would need to convert the numbers to daily return first. And then I want to find out the average return for everyday (hope that make sense to you).

      If you can either reply the syntax here or email to me at [email protected], I would be very appreciated!

      Cheers,
      Chris
      Attached Files

      Comment


      • #4
        Chris: Please note FAQ Advice #12 and #15 on showing the syntax you tried, on not posting .dta and on not asking for private replies.

        12. What should I say about the commands and data I use?

        Help us to help you by producing self-contained questions with reproducible examples that explain your data, your code, and your problem. This helps yet others too, as they will find it easier to learn from your questions and the answers to them.

        12.1 What to say about your commands and your problem

        Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!

        If you are using user-written commands, explain that and say where they came from: the Stata Journal, SSC, or other archives. This helps (often crucially) in explaining your precise problem, and it alerts readers to commands that may be interesting or useful to them.

        Here are some examples:

        I am using xtreg in Stata 13.1.
        I am using estout from SSC in Stata 13.1.
        Never say just that something "doesn't work" or "didn't work", but explain precisely in what sense you didn't get what you wanted.

        12.2 What to say about your data

        We can understand your dataset only to the extent that you explain it clearly.

        The best way to explain it is to show an example. The user-written command dataex makes it easy to give simple example datasets in postings. It was written to support Statalist and its use is strongly recommended. Usually a copy of 20 or so observations from your dataset is enough to show your problem.

        You must install dataex before you can use it. Type ssc install dataex in your Stata and follow by looking at help dataex.

        The merits of dataex are that we see your data as you do in your Stata. We see whether variables are numeric or string, whether you have value labels defined and what is a consequence of a particular display format. We can copy and paste easily into our own Stata to work with your data.

        If your dataset is confidential, then provide a fake example instead.

        The second best way to explain your situation is to use one of Stata's own datasets and adapt it to your problem. Examples are the auto data and the Grunfeld data (a simple panel dataset). That may be more work for you and you may not find an analog of your problem with such a dataset.

        The worst way to explain your situation is to describe your data vaguely without a concrete example. Note that it doesn't help us much even to be given your variable names. Often that leaves unclear both your data structure and whether variables are numeric or string or their exact contents. If you explain only vaguely, quick answers to your question, or even any answers at all, are less likely.

        12.3 How to use CODE delimiters

        Stata code (i.e. the exact commands issued) is very much easier to read if presented as such.

        When you are editing an answer you should see a # button in the toolbar above the text area. Click on # to insert
        Code:
         and
        mark-up. Write your code between, paying particular attention to linebreaks and indentation.

        If you do not see that button, then click on the “Toggle Advanced Editor” button (an underlined A) in the area above to show the toolbar.

        If you do not have access to the Advanced Editor in your interface, you can just insert those mark-ups manually before, or indeed after, you insert your code. Many people fast at typing do that any way.

        Examples of your data (or of realistic similar datasets) are also much easier to read if presented as CODE. dataex, explained just above, automatically generates text including CODE delimiters, which can be copied and pasted into Statalist posts.

        What is valuable with presenting code or data as CODE is that other members can easily copy and paste what you post to play with in their Stata installation.

        12.4 Posting image attachments: please do use .png

        Stata graphs or other images should be posted as .png file attachments (start with the Clipboard icon).

        12.5 Posting attachments: please don't...

        There are several "please don't" requests here, but good reasons for them all.

        Please do not post .gph files, as they can't be read without flipping back and forth between Stata and the forum software, thus making your posts much more difficult to follow.

        In particular, please do not post screenshots. Many members will not be able to read them at all; they usually can't be read easily; and they do not allow copy and paste of data or code, which is highly desirable to allow experienced members to make precise suggestions for your questions.

        You are asked not to post attachments that are in Word or Excel file formats (.doc, .docx, .xls, .xlsx), because

        many members just don't have or don't use such software
        obliging other members to open those programs to see your problem is at best awkward and indirect
        many members have zero-risk policies on not opening such files from third parties
        there are better ways to show the information, as explained just above.
        Finally, we ask that in general you don't post .dta or .zip files either. This is because

        as above, it obliges members to fire up Stata (and/or some other program) with your file to see the problem, which could be difficult or time-consuming if you have a large or complicated dataset
        members may have versions of Stata earlier than yours such that they can not read your .dta files anyway
        threads become more difficult to understand if they depend on people reading in a dataset: short code and data examples are much easier to work with, as explained above.


        15. May I ask for private replies?

        Please do not request private replies unless you are posting about employment or consultancy opportunities. Statalist is based on replying to the forum, not personally to the poster, with the ideal that postings are of interest to many.


        Comment

        Working...
        X