-2

I want to make a sample of two variables, according to a specific probability distribution. I thought of making a matrix that expresses the probability distribution but my code results in "p is not defined". // p = matrix(c(0.04,0.1,0,0.06,0.05,0.3,0,0.05,0.14,0.1,0.06,0.1), nrow=3, ncol=4, byrow = TRUE) sample_100 = rDiscrete(n=50000,pf=p) // How can I fix this?

Max
  • 1
  • 2
  • 2
    Looks to me as if you are using R or R-like syntax in Stata. That's not going to work. – Nick Cox Oct 20 '20 at 20:15
  • I see... What is a STATA way then? – Max Oct 21 '20 at 02:52
  • If you have access to Stata start with `help matrix`. – Arthur Morris Oct 21 '20 at 03:55
  • You got a good answer, but a better question would show some attempt at code in the language you're asking about. Otherwise Stack Overflow would be swamped with questions of the form: What is the code for task X in language Y? – Nick Cox Oct 21 '20 at 08:47
  • @NickCox’s point is a very good one! – Arthur Morris Oct 21 '20 at 11:30
  • Thank you everyone! Well it still says "'p' found where '(' expected"... I want to create a random sample of two variables, and with a matrix of probability distribution is already given. I have no idea how to implement that. – Max Oct 21 '20 at 12:46
  • 2
    Assuming that you are trying to use Stata, you are giving us an error message, but no code. Please edit your question to show Stata code, or ask a new question. – Nick Cox Oct 21 '20 at 12:57

1 Answers1

2

Here is one way to create the matrix in your matrix() command:

matrix input p = (0.04,0.1,0,0.06 \ 0.05,0.3,0,0.05 \ 0.14,0.1,0.06,0.1)

This answers the question in the title of your post. If you provide more information about your question, you may be able to elicit a more complete answer.

As I mentioned: help matrix will give you the documentation, which will help you.

Arthur Morris
  • 1,253
  • 1
  • 15
  • 21