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 9129555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:46:36+00:00 2026-06-17T07:46:36+00:00

Being fairly new to Stata, I’m having a difficulty figuring out how to do

  • 0

Being fairly new to Stata, I’m having a difficulty figuring out how to do the following:

I have time-series data on selling price (p) and quantity sold (q) for 10 products in a single datafile (i,e., 20 variables, p01-p10 and q01-q10). I am strugling with appropriate stata command that computes sales revenue (pq) time-series for each of these 10 products (i.e., pq01-pq10).

Many thanks for your help.

  • 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-06-17T07:46:37+00:00Added an answer on June 17, 2026 at 7:46 am
    forval i = 1/10 { 
          local j : display %02.0f `i' 
          gen pq`j' = p`j' * q`j' 
    }
    

    A standard loop over 1/10 won’t get you the leading zero in 01/09. For that we need to use an appropriate format. See also

    @article {pr0051,
    author = “Cox, N. J.”,
    title = “Stata tip 85: Looping over nonintegers”,
    journal = “Stata Journal”,
    publisher = “Stata Press”,
    address = “College Station, TX”,
    volume = “10”,
    number = “1”,
    year = “2010”,
    pages = “160-163(4)”,
    url = “http://www.stata-journal.com/article.html?article=pr0051”
    }

    (added later) Another way to do it is

    local j = string(`i', "%02.0f") 
    

    That makes it a bit more explicit that you are mapping from numbers 1,…,10 to strings “01”,…,”10″.

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

Sidebar

Related Questions

Being fairly new to programming, I am having trouble understanding exactly what Homebrew does...
Being fairly new to C++ I have a question bascially concerning the g++ compiler
Fairly new to Jquery here.... but one thing I have been told and being
Being fairly new to Spring I have a question about annotating a class. When
Being fairly new to objective-c and developing for ios I'm trying to figure out
The Information: So I am fairly new to .htaccess and have being reading a
First let me state that, despite being a fairly new practitioner of TDD, I'm
After reading Jeff's blog post and being fairly new to GUI programming, I'm wondering
I'm confused as to the difference. Being fairly new to .Net, I know I
I am fairly new to JQuery. That being said I am trying to use

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.