Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: forvalues problem


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: forvalues problem
Date   Sun, 26 Aug 2012 07:50:53 +0100

Several errors here:

1. Evaluate r(N):

local nmbr = r(N)

Otherwise you are just copying the text "r(N)", not a good idea.

2. -in 1- is misplaced in the -replace- statement; it must be placed after the expression. Study the syntax diagram for -replace-.

3. The statement -local back ...- won't work for various reasons. You apparently intend something like

local back = ptile['i' - 1]

4. You must use 'back' to evaluate a local macro. This error was very recently explained to you.

Please note that I don't have a left single quote character on the device I am using.

These are the syntax or style errors evident on a quick reading.

Writing a loop to get a cumulative sum is also unnecessary as the function -sum()- will do that for you. But each cumulative probability is just _n/_N after sorting, although a decent program would need to think about ties and missing values
and support -if- and -in-.

Writing a do-file or program to draw a cumulative distribution plot is also unnecessary as (e.g.) -distplot- (SJ) has already been written.

Nick


On 26 Aug 2012, at 00:19, Morrison Hodges <[email protected]> wrote:

I have the following code:
----------------------------------
/*                  cdp.do

   Creating a cumulative distribution plot for use in PreFib analysis
   Created by MH on Friday, August 23, 2012
                                   */
version 12.1

capture log close
set more off

use prefib.dta, clear

label data "PreFib Data"

summarize grpa_jumpnmbr /* to get the number of rows in grpa_jumpnmbr */ local nmbr r(N) /* gets the number of rows in grpa_jumpnmbr */ sort grpa_jumpnmbr /* sorts grpa_jumpnmbr from lowest to highest */ gen ptile = 0 /* new variable to place percentiles in */ gen dif = 1/`nmbr' /* generates the percentile difference to be added to each row */ replace ptile in 1 = dif /* lowest number is the lowest percentile */

forvalues i = 2/`nmbr' {

   local back = (ptile in (`i' - 1))
   replace ptile in `i' = back + dif

}

log close
---------------------------------------
I get a syntax error with this, but I don't know why. Thanks in advance for any help.


*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index